I have a table setup, now I want to pull a query from a MySQL database and put in 4 columns, and then then make a new row in HTML and enter in the next 4 columns of data, and have it a repeating process.
How do I go about doing so?
Limiting HTML Rows From An Query
Moderator: General Moderators
Code: Select all
<table>
<?$my_query = "SELECT * FROM table" or die ("error in query");
$my_result = mysql_query($my_query) or die ("error in result");
while ($my_row = mysql_fetch_array($my_result)) {
echo "<tr><td>$my_rowї"column_1"]</td><td>$my_rowї"column_2"]</td><td>$my_rowї"column_3"]</td><td>$my_rowї"column_4"]</td></tr>\n" ;
}
?>
</table>Not What I Am Looking For
I want to be able to print out 4 columns in tables, then make another row and have another 4 columns in tables printed, and etc.
See if this does it for you.
Code: Select all
<table>
<tr>
$cnt=1;
// loop for each item in array
while ($row = mysql_fetch_array($result)) {
?>
<td>
<? echo $rowї"somevalue"];?>
</td>
<?
if (!($cnt%4)){
echo "</tr><tr>";
}
$cnt++;
}
?>
</tr>
</table>