[SOLVED] Empty result sets killing the whole loop
Posted: Fri Nov 07, 2003 3:28 pm
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.
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.
Code: Select all
$sql="SELECT * FROM $table_hymns ORDER BY $order_by";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result) or die(mysql_error());
do {
?>
<tr>
<td class=mainTable><a href="hymns.php?id=<?php echo $myrowї"id"] ?>"><?php echo "#" . $myrowї"id"] . " - " . $myrowї"title"] ?></a></td>
<td class=mainTable><?php echo $myrowї"category"] ?></td>
<td class=mainTable>
<?php
$sql_a="SELECT * FROM $table_hymns_sundays WHERE openingsong='$myrowїid]' ORDER BY sunday DESC LIMIT 1";
$result_a = mysql_query($sql_a) or die(mysql_error());
$numrows_a = mysql_num_rows($result_a);
$myrow_a = mysql_fetch_array($result_a) or die(mysql_error());
echo $myrow_aї"sunday"];
?></td><td class=mainTable><?php
$sql_b="SELECT COUNT(*) FROM $table_hymns_sundays WHERE openingsong='$myrowїid]' OR sacramentsong='$myrowїid]' OR restsong='$myrowїid]' OR closingsong='$myrowїid]'";
$result_b = mysql_query($sql_b);
$myrow_b = mysql_fetch_array($result_b) or die(mysql_error());
if ($myrow_bї"COUNT(*)"]) {
echo $myrow_bї"COUNT(*)"];
}
?>
</td></tr><?php
} while ($myrow = mysql_fetch_array($result)); // end do...while loop