DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Michael has posted 27 posts at DZone. View Full User Profile

Display Data In Table - PHP MySQL

12.12.2006
| 464 views |
  • submit to reddit
        // Display multiple records in a table format from mysql table

<?
$sql = mysql_query("SELECT * FROM table WHERE this = '$this'");
?>

<table width="600px" border="0" cellspacing="1" cellpadding="2">
 <tr>
  <td>Column1</td>
<td>Column2</td>
</tr>
  
<?
$total_rows = mysql_num_rows($sql);

for($ith=0;$ith<$total_rows;$ith++)
{

$sql_field1 = mysql_result($sql,$count,"sql_field1");
			 
?>
 <tr>
    <td><? echo $column1; ?></td>
	
	<td><? echo $column2;; ?></td>
	
  </tr>

<?
$count++;
?>

<?
}
?>
</table>