...

View Full Version : Accessing mySQL query results with php



simbarashe
04-01-2007, 04:38 PM
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

Fumigator
04-01-2007, 06:33 PM
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.



$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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum