Second condition causes first cobdition to fail
Posted: Wed Dec 24, 2003 6:12 pm
(Had a little trouble coming up with a meaningful title for this post.) Anyway, consider the following code:
The $Query assignment on the first line within the while loop is failing, and firther examination using print_r($Row) and print($Query) statements shows that $Row is empty and $Query is merely (as you would expect what with $Row being empty) "SELECT * FROM Stores WHERE id="
Note, however, that the while loop is iterating the expected number of times. That is, when the initial query returns two rows the while loop iterates twice.
But if I leave off the second condition like so:
then $Row and Query are completed correctly.
I can use LIMIT in the query, of course, which is actually a better way to do the process, and there are several other workarounds. But, why does the addition of the second condition kill the first?

Code: Select all
<?php
$Query = "SELECT * FROM Reports WHERE Assn=40 AND (Date>'$Sdate' OR Stat=0)";
$Result = mysql_query($Query, $Link);
$Cntr = 0; // we are just printing the first eight stores
while ($Row = mysql_fetch_array($Result) && $Cntr <
{ $Query = "SELECT * FROM Stores WHERE id=" . $Row['Sid'];
$Sresult = mysql_query($Query, $Link);
$Srow = mysql_fetch_array($Sresult);
// etcetera, rest doesn't matter
?>Note, however, that the while loop is iterating the expected number of times. That is, when the initial query returns two rows the while loop iterates twice.
But if I leave off the second condition like so:
Code: Select all
<?php
while ($Row = mysql_fetch_array($Result))
{ $Query = "SELECT * FROM Stores WHERE id=" . $Row['Sid'];
?>I can use LIMIT in the query, of course, which is actually a better way to do the process, and there are several other workarounds. But, why does the addition of the second condition kill the first?