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

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.

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.