Siggles Posted February 11, 2008 Share Posted February 11, 2008 For example, I have a while loop from the result of a select statement. If that select statements gets a result I want the column headers to display once and then it to list the results of the while loop. So far I have this... while($row = mysql_fetch_array($result)) { $counter=1; if($counter=1) { echo "<tr> <td><u>Date Played</u></td></tr> $counter++; } echo "<td>".$row['example']."</td>"; This works okay but what if the while loops yields nothing and instead I want it to display, 'nothing found' instead of the column headers. Can you use an isset with a while loop? Not sure which is the best way to do this. Any help would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/90563-display-column-headers-once-in-while-loop/ Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 The mysql_num_rows returns the number of rows found for the query you select within the parenthesis. If it returns 0, then there is no rows or data found, else it will run the loop within the "else". <?php if(mysql_num_rows($query)==0){ echo "Nothing Found"; }else{ // Do the Loop. } ?> Link to comment https://forums.phpfreaks.com/topic/90563-display-column-headers-once-in-while-loop/#findComment-464325 Share on other sites More sharing options...
Siggles Posted February 11, 2008 Author Share Posted February 11, 2008 Thanks, works. Link to comment https://forums.phpfreaks.com/topic/90563-display-column-headers-once-in-while-loop/#findComment-464346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.