graham23s Posted July 1, 2007 Share Posted July 1, 2007 Hi Guys, i use this while loop to echout all my categories at once, but is there a way i could have them echo out in a table say 5 across at a time? ## cat browse ################################################################### $query_browse = mysql_query('SELECT `id`, `name` FROM `categories` ORDER BY `name` ASC'); while ($category = mysql_fetch_assoc($query_browse)) { $cat_id_gif = $category['id']; echo '<a href="browse_files.php?cat_id='.$category['id'].'">'.$category['name'].'</a> <b>|</b> '; } ## cat browse ################################################################### thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/57981-echoing-out-a-while-in-a-table/ Share on other sites More sharing options...
GingerRobot Posted July 1, 2007 Share Posted July 1, 2007 If you mean you want to have 5 results on a line, then a new line etc, then take a look at this post: http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Link to comment https://forums.phpfreaks.com/topic/57981-echoing-out-a-while-in-a-table/#findComment-287391 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Try this out: <?php $query_browse = mysql_query('SELECT `id`, `name` FROM `categories` ORDER BY `name` ASC'); $count = 1; echo '<table cellpadding=7>'; while ($category = mysql_fetch_assoc($query_browse)) { $cat_id_gif = $category['id']; if ($count == 5){ echo '<tr>'; $count = 0; } echo '<td><a href="browse_files.php?cat_id='.$category['id'].'">'.$category['name'].'</a></td>'; $count++; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/57981-echoing-out-a-while-in-a-table/#findComment-287392 Share on other sites More sharing options...
GingerRobot Posted July 1, 2007 Share Posted July 1, 2007 Poco, you forgot to close any of the table rows Link to comment https://forums.phpfreaks.com/topic/57981-echoing-out-a-while-in-a-table/#findComment-287395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.