Printing DB fields to table columns
Posted: Thu May 22, 2003 9:39 am
How can i simplify this? I want to print contents of a rows from MySQL into a table so, that each value of a field prints to a table cell horizontally and when next row starts from db it prints to next table row. How can i do it so, that i dont need to specify a number of columns, but column number is automatically a number of fields in a row?
Here's the code
I would appreciate any help.
?>
Here's the code
Code: Select all
<?php
$field_list = mysql_query("SELECT * FROM $table") or die(mysql_error());
if(mysql_num_rows($field_list)) {
print "<table border=1 cellspacing=0>\n";
while($field = mysql_fetch_array($field_list)) {
print "<tr><td>".$field['0']."</td><td>".$field['1']."</td><td>".$field['2']."</td>
<td>".$field['3']."</td><td>".$field['4']."</td><td>".$field['5']."</td>
<td>".$field['6']."</td><td>".$field['7']."</td><td>".$field['8']."</td>
<td>".$field['9']."</td><td>".$field['10']."</td></tr>";
}
print "</table>";
?>?>