Jump to content

Display column headers once in while loop


Siggles

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.