Hi all, I ran into a very odd problem today and I've been staring at it a lot, to no avail, so far.
I'm using a standard while loop with mysql_fetch_array to iterate through a result set from a MySQL query. The way it's supposed to work is that, when the value returned from that function is FALSE, the while loop is done.
What happens in this one case now is that the loop never breaks. Rather, the whole program stops. Any code or HTML that appears after my while block is not executed or printed. However, all the results from the SQL query itself seem to be fine. It's like the loop knows where to stop, but then it acts as if the whole program is done. I see no error messages in the web server log.
At first suspecting I was in some sort of infinite loop, I inserted a statement to return the number of rows, which returned 6, the same as the query executed at the MySQL command line returns and the same number that appears printed out from my loop code.
Very weird. All the other times I've used this, it's always behaved just as expected.
Here's the basic code:
<?php
// connect to the db
$db = mysql_connect("localhost", "root", "firedept") or die(mysql_error());
mysql_select_db("dbName",$db) or die(mysql_error());
$sql = "SELECT field1, field2, field3 FROM Table;";
$result = mysql_query($sql,$db);
$num_rows = mysql_num_rows($result);
print "<p>This query has $num_rows rows...</p>";
print "<ul>";
while ($myrow = mysql_fetch_assoc($result) or die(mysql_error()) ) {
$value1 = $myrow['field1'];
$value2 = $myrow['field2'];
$value3 = $myrow['field3'];
print"<li>Field1: $value1; Field2: $value2; Field3: $value3</li>";
}
print "</ul>";
?>
Thanks, all...