Jump to content

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";

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.