displaying mysql data in a html table

A

Anonymous

Guest
Please use the board's
PHP:
 tags when posting code.

Your problem is that you're not outputting the table data inside the while() loop, so it will only show the data from the last row.
 
when you are within your while loop, you have statements like:
$text = ???;

when you finally exit out of your loop and print the $text variable, it will only have the last value you put into it. For it to work, you might want to try starting your table, next loop through your data and print the rows within the loop, and then close your table tag after your loop.
 
PHP:
<?php
$query = mysql_query("SELECT * FROM news"); 

if (mysql_num_rows($query) == 0) {
  print '<center><p>Sorry, No news in this section yet.</p></center>';
}
else{
  while($row = mysql_fetch_array($query)){ 

   print '<table width="100%" border="0" cellpadding="0" cellspacing="0">
               <tr>
                 <td background="bg_nav.jpg" bgcolor="#B8B8B8"><b>News: </b>' . $row[title] . '</td>
               </tr>
               <tr>
                 <td>' . $row[text] . '</td>
               </tr>
               <tr>
                 <td>Submitted by: ' . $row[name] . '</td>
               </tr>
           </table>';
  }
}
?>
 
Back
Top