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 Quote Link to comment 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. } ?> Quote Link to comment Share on other sites More sharing options...
Siggles Posted February 11, 2008 Author Share Posted February 11, 2008 Thanks, works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.