SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Separate function to process database results

    I'm working on a new site and repeatedly using chunks of very similar code to process database results.

    What would be the best way to send the results to a function for processing so that the same code could be re-used?

    What I am trying - so far without sucess is along the lines of the following:

    Extract 1
    PHP Code:
    $result=@mysql_query("SELECT * FROM business_listings WHERE business_name LIKE '%".$searchname."%' ORDER by business_name"); 

    Extract 2
    PHP Code:
    while ($row mysql_fetch_array($result)) {
    WriteToSpans ($result); 
    Extract 3
    PHP Code:
    function WriteToSpans ($result) {
    $db_business_name=$row['business_name'];
    $db_business_address_line1=$row['business_address_line1'];
    echo 
    $db_business_name;

    Hope the above isn't too stupid or far off the mark. Any advice would be very welcome and much appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a close look at the variables you are passing in to the function, and trying to use.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •