PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I think an empty result set from an SQL statement inside my do...while loop kills the do...while loop from continuing.
Basically my do...while outputs a table of rows, but for a couple of the cells in that row I want to do other SQL SELECTs. However, as soon as any of those SELECT statements returns an empty set (at least this is my theory), the master do...while loop just stops running. So, for example, in a table that should have 341 rows, I only get the first two rows.
What can I do to keep the outer do...while loop running even if a nested SELECT statement gets no results? Or is this not my problem? Any ideas will be greatly appreciated.
I wasn't really sure what you were suggesting, but it sort of made sense after I read the manual about the reset() and list() functions. I put the caching code before my do statement, like this:
<?php
$sql="SELECT * FROM $table_hymns ORDER BY $order_by";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result) or die(mysql_error());
// php side result caching:
while($myrow = mysql_fetch_array($result)) $res_arr[]=$myrow;
$myrow=$res_arr[0];
reset($res_arr);
do {
//...
and changed my while statement to the one you recommended, like this:
But now I only get one row from the do...while. Again, I am running SQL statements inside my do...while loop. These SQL statements sometimes return no result set. As soon as that happens, the outer do...while loop kills.
I wasn't sure what to do with the $key part. Am I supposed to be sending some value as $key?
Try using the die() statement within the mysql_query() function instead. That should work.
The manual only shows examples of die() being used within the mysql_connect(), and mysql_query(), and similar functions. Since the mysql_fetch_array() isn't doing any database querying there should not be any error to report in that sence.