Jump to content

[SOLVED] Using php to creat a table


MemphiS

Recommended Posts

I wish to create a table with x boxs times x amount.

 

I grab the information from the database.

 

<?php
$r = mysql_query("SELECT `id` FROM `table`");
while ($t = mysql_fetch_row($r)){
echo("<td width=50 height=50>$t[0]</td>");
}
?>

 

The problem is i need to insert a <tr></tr> every 10 times it echos out echo("<td width=50 height=50>$t[0]</td>");

 

Im a bit puzzled on what to do.  I was thinking a count variable.  But im going to have 1000 rows and dont really want to write something like:

 

if ($count==10){ echo("<tr>"); }

 

or

 

if (in_array($count,$splitnums,true)){ echo("<tr>"); }

 

Is there a better way?

Link to comment
https://forums.phpfreaks.com/topic/84098-solved-using-php-to-creat-a-table/
Share on other sites

here you go

 

 

<?php
$r = mysql_query("SELECT `id` FROM `table`");

echo "<table><tr>";
$i = 0;
while ($t = mysql_fetch_row($r)){
$i++;
echo("<td width=50 height=50>$t[0]</td>");
if (($i%10)==0)) { echo "</tr><tr>"; }
}

echo "</tr></table>";
?>

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.