Hi chaps,
I'm having a bit of difficulty and can't seem to get my head around the issue I'm experiencing! As usual have done lots of web searches but haven't managed to turn up the answer.
I have a query that is returning two rows from the database (confirmed by running the query in MySQL query browser).
Here's my code:
In reality I'll want to do something slightly more sensible than echo the word "test" of course but I'm using this as proof that the loop is picking up two rows from the database. Now, when I run the above code, it only outputs the word "test" once.PHP Code:$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server!");
mysql_select_db($database,$connection)
or die ("Couldn't select database!");
/* Execute query to retrieve repairs */
$sql = "SELECT t2.flat_number,t1.title_of_repair,t1.created_date_time,t3.firstname,t3.lastname
FROM properties t2
LEFT OUTER JOIN repairs t1 ON t1.property_id=t2.property_id
INNER JOIN users t3 on t3.userid=t1.created_by
WHERE t1.assigned_to_user=$_SESSION[userid] AND t1.signed_off=0";
$result = mysql_query($sql)
or die ("Couldn't execute query!");
while($row = mysql_fetch_array($result,MYSQL_ASSOC));
{
echo "test";
echo "<br />";
}
To be absolutely sure two records are being returned from the query I changed my code for the following in place of the while loop:
When I run the above code sure enough I can see two arrays containing data corresponding to the two rows returned by the query.PHP Code:$var1 = mysql_fetch_row($result);
$var2 = mysql_fetch_row($result);
print_r($var1);
echo "<br />";
print_r($var2);
Why won't the while loop work. No doubt a silly error on my part but it's driving me crazy!
Hopefully somebody can help?
Cheers
Chris.




Reply With Quote
Bookmarks