Jump to content

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

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.