jesushax Posted April 8, 2008 Share Posted April 8, 2008 the while function loops through records yes? so if there is nothing to loop through what can i put, it doesnt like else this is what i mean this doesnt work...? while ($row = mysql_fetch_array($SQL)) { im loopign records here } else { echo "There are no current records."; } Link to comment https://forums.phpfreaks.com/topic/100102-quick-while-question/ Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 Method A (most common) <?php if (mysql_num_rows($SQL) > 0) { while ($row = mysql_fetch_array($SQL)) { // im looping records here } } else { echo "There are no current records."; } ?> Method B <?php if ($row = mysql_fetch_array($SQL)) { // returns false if no record do { // im looping records here } while ($row = mysql_fetch_array($SQL)); // use do..while so first row gets processed in the loop } else { echo "There are no current records."; } ?> Link to comment https://forums.phpfreaks.com/topic/100102-quick-while-question/#findComment-511850 Share on other sites More sharing options...
jesushax Posted April 8, 2008 Author Share Posted April 8, 2008 thanks! Link to comment https://forums.phpfreaks.com/topic/100102-quick-while-question/#findComment-511862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.