MemphiS Posted January 2, 2008 Share Posted January 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84098-solved-using-php-to-creat-a-table/ Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2008 Share Posted January 2, 2008 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84098-solved-using-php-to-creat-a-table/#findComment-428071 Share on other sites More sharing options...
MemphiS Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks rajivgonsalves, exactly what i needed Quote Link to comment https://forums.phpfreaks.com/topic/84098-solved-using-php-to-creat-a-table/#findComment-428079 Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2008 Share Posted January 2, 2008 Your welcome glad to be of help!! Quote Link to comment https://forums.phpfreaks.com/topic/84098-solved-using-php-to-creat-a-table/#findComment-428081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.