Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing mySQL query results with php

    Hie

    Could some1 please help me with sorting my mySQL query in php. It is as follows:

    $requestID = $_GET['requestID'];
    $follNumber = $_GET['id'];
    $follUpInfo = mysql_query("SELECT time_assigned,date_assinged,assStaffID,
    staffID FROM FOLLOW_UP
    WHERE FOLLOW_UP.requestID= '$requestID'
    ORDER BY followUpID DESC ")
    or die (mysql_error());
    $rows = mysql_fetch_array($follUpInfo);

    This query can get more than one result and The result that I want to access is determined by the $follNumber Variable. so when I use

    $rows[x];

    it gets the information contained in the first row only but I might be looking for whats in the second or third row. Should I change my query or the way I am sorting the results?

    Could someone please help me, I am stumped

    Thanx

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You just need to put your mysql_fetch_array() call in a loop. The function only retrieves one row from the result set at a time.

    PHP Code:
    $requestID $_GET['requestID'];
    $follNumber $_GET['id'];
    $follUpInfo mysql_query("SELECT time_assigned,date_assinged,assStaffID,
    staffID FROM FOLLOW_UP
    WHERE FOLLOW_UP.requestID= '$requestID'
    ORDER BY followUpID DESC "
    )
    or die (
    mysql_error());
    for (
    $i 0$i mysql_num_rows($follUpInfo); $i++) {
        
    $rows[$i] = mysql_fetch_array($follUpInfo);
    }

    //display the array you just built (for fun)
    print "<pre>\n";
    print_r($rows);
    print 
    "<\pre>\n"
    p.s. in the future please use the [ PHP ] [ /PHP ] tags when posting code (without the spaces), it's much easier to read


  •  

    Posting Permissions

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