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 Quote Link to comment 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 Quote Link to comment 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>'; ?> Quote Link to comment 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 Quote Link to comment 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.