simcoweb Posted February 5, 2007 Share Posted February 5, 2007 I'm creating a classifieds system and need to list the categories in say a 3 column layout. I know how to 'while' loop through an array to display rows. In this case, however, I need to display the categories in a table where each cell is a separate item instead of the row constituting a record/row from the database. Should look like: Category 1 Category 2 Category 3 Category 4Category 5Category 6 Category 7Category 8Category 9 etc. There would also be some sub-cats displayed in each cell as well. What i'm looking for is the coding that would create a table row when needed and how it would place the results starting left-to-right for as many cells/rows as needed. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 5, 2007 Share Posted February 5, 2007 are your columns fixed? so you can have one while loop, and inside that while loop, echo each column in the row... would that work in your case? Ted Quote Link to comment Share on other sites More sharing options...
Xinil Posted February 5, 2007 Share Posted February 5, 2007 Quick write up: $totalColumns = 5; $i = 1; echo '<table border="1">'; for ($b=0;$b<15;$b++) { if ($i == 1) echo '<tr>'; echo '<td>'; echo 'item' ,$i; echo '</td>'; if ($i == $totalColumns) { echo '</tr>'; $i = 0; } $i++; } echo '</table>'; Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 5, 2007 Author Share Posted February 5, 2007 Xinil, thanks for that example. I can understand it as it applies to incrementing the number of cells needed per column. I see you have, in your example, $totalColumns set to 5. I'd probably change that to 3 and I don't see anywhere else in your example where that would affect anything. Ted, i'm looking at whatever works best. If I made the columns a fixed number then i'd like to see the code snippet that would display it that way. Could you please? Thanks to both of you Quote Link to comment Share on other sites More sharing options...
Xinil Posted February 5, 2007 Share Posted February 5, 2007 Of course, simcoweb. Just change the totalColumns to 3 and everything will work the exact same. 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.