gfX Posted February 5, 2007 Share Posted February 5, 2007 Hello. What I am trying to do, is have 12 total layouts showing. 3 rows of 4. I am using tables for this, and it is generated using PHP. <table border="0" cellspacing="0" cellpadding="1" align="center"> <?php $sql = mysql_query("SELECT * FROM `layouts` ORDER BY `id` ASC"); $i = 0; while ($r=mysql_fetch_assoc($sql)) { $i++; $id = $r['id']; $title = $r['title']; $code = $r['code']; $thumbnail = $r['thumbnail']; if (($i == 5)) { echo "<tr>"; } echo "<td width='25%' align='center' valign='top'> <a href='http://www.layoutslife.com/code.php?id=$id'> <img src='http://www.layoutslife.com/thumbnails/$thumbnail' border='0' width='160' height='120' /></a> <br /><b>$title</b><br /></td>"; if (($i == 5)) { echo "</tr>"; } } ?> </table> That's the code I have, which I know is definitely wrong because it isn't working! Does anyone know how I can get this done? Here is a screenshot of how it displays with my current code: Thanks Link to comment https://forums.phpfreaks.com/topic/37113-need-help-php-and-tables/ Share on other sites More sharing options...
btherl Posted February 5, 2007 Share Posted February 5, 2007 A good way to do this is to start with "<tr>", and then to do this if ($i > 0 && $i % 5 == 0) { print "</tr><tr>"; } Then at the end of it all, add a "</tr>" Link to comment https://forums.phpfreaks.com/topic/37113-need-help-php-and-tables/#findComment-177255 Share on other sites More sharing options...
gfX Posted February 5, 2007 Author Share Posted February 5, 2007 Soooooo.. <table border="0" cellspacing="0" cellpadding="1" align="center"> <tr> <?php $sql = mysql_query("SELECT * FROM `layouts` ORDER BY `id` ASC"); $i = 0; while ($r=mysql_fetch_assoc($sql)) { $i++; $id = $r['id']; $title = $r['title']; $code = $r['code']; $thumbnail = $r['thumbnail']; if ($i > 0 && $i % 5 == 0) { print "</tr><tr>"; } echo "<td width='25%' align='center' valign='top'> <a href='http://www.layoutslife.com/code.php?id=$id'> <img src='http://www.layoutslife.com/thumbnails/$thumbnail' border='0' width='160' height='120' /></a> <br /><b>$title</b><br /></td>"; } ?> </tr> </table> ?? Almost there, Preview at: www.layoutslife.com Link to comment https://forums.phpfreaks.com/topic/37113-need-help-php-and-tables/#findComment-177257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.