PHPTOM Posted January 21, 2009 Share Posted January 21, 2009 Hi, Im wanting a table to function like this: *table coding* <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> I basically want it to go to a new row once it hits 4 items on the current row. Any ideas on how to do this? I'm off to school now, but I will be sure to have a read when I get in if anyone replies Thanks Quote Link to comment https://forums.phpfreaks.com/topic/141726-displaying-only-so-many-items-in-a-row-of-a-table/ Share on other sites More sharing options...
Philip Posted January 21, 2009 Share Posted January 21, 2009 <?php // settings: $number_of_rows = 6; $number_of_columns = 4; // start table echo '<table><tr>'; // count number of elements, and divide by columns to get row count for($i=0; $i/$number_of_columns<$number_of_rows; $i++) { // if new row if($i%$number_of_columns==0) echo '</tr><tr>'; // show box. echo '<td>',$i,'</td>'; } echo '</tr></table>'; ?> That'll make: 0123 4567 ... Quote Link to comment https://forums.phpfreaks.com/topic/141726-displaying-only-so-many-items-in-a-row-of-a-table/#findComment-741946 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.