Jump to content

Create a new row every when $i = 5


samtwilliams

Recommended Posts

I am trying to draw a table dynamically, I need a table that is 5 x 5, i know i'm close quite my code by just can't quite fathom it out. My sql returns 25 results which i want to return 25 cells in a square table.

 

<?PHP
$i = 0;
while($row = mysql_fetch_assoc($result)) {
$i++;
?>
<?PHP
if($i== 5) {
echo '<tr>';
}
?>
<td class="right bottom"><?PHP echo $row['GridID']; ?></td>
<td class="right bottom"> </td>
<td class="right bottom"> </td>
<td class="right bottom"> </td>
<td class="bottom"> </td>


<?PHP
if($i== 5) {
echo '</tr>';
$i=0;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/273954-create-a-new-row-every-when-i-5/
Share on other sites

or use floating divs, 20% wide

 

echo "<div style='width:200px'>\n";
for ($i=1; $i<=25; $i++) {
   echo "<div style='width:20%; float:left; text-align:center; border:1px solid gray;'>
   $i
   </div>";
}
echo "</div>\n";

echo "<table border='1' style='width:200px; border-collapse:collapse;'>\n";
echo "<tr>";
for ($i=1; $i<=25; $i++) {
echo "<td style='text-align:center; '>
$i
</td>";
if ($i%5==0)
	echo "</tr><tr>";
}
echo "</tr></table>\n";

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.