pouncer Posted February 27, 2007 Share Posted February 27, 2007 At the moment, I've got something like this. echo " <table width=90% cellpadding=0 cellspacing=1 border=0 align=center> <tr> <th>Item</th> <th>Description</th> </tr>"; while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) { echo " <tr> <td>$item_name</td> <td>$item_description</td> </tr>"; } echo "</table>"; But I want to change the table layout. I want to make a 3 by 3 table (9 slots) and put all the data in 1 slot at a time, can someone show me how to change the table layout? Link to comment https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/ Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 Try: <?php echo "<table width=90% cellpadding=0 cellspacing=1 border=0 align=center>\n"; echo "<tr>\n"; echo "<th>Item</th>\n"; echo "<th>Description</th>\n"; echo "<th>Slot 3</th>\n"; echo "</tr>"; for ($i = 0; $row = mysql_fetch_array($sql, MYSQL_ASSOC); $i++) { if($i%3 == 0) echo "<tr>"; echo "<td>".$item_name."</td>"; echo "<td>".$item_description."</td>"; echo "<td>Slot 3</td>"; if($i%3 == 0) echo "</tr>"; } echo "</table>"; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/#findComment-195214 Share on other sites More sharing options...
pouncer Posted February 27, 2007 Author Share Posted February 27, 2007 ahhh, i see now mate. very nice. I was looking at how i could add a counter for each record like you added $i in the for loop. thanks! and also % is mod? which calculates the remainder?i just noticed you have if($i%3 == 0) twice :s and also, shouldnt i start at 1? since if its 0, it will display 0 1 2 3 which is 4? Link to comment https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/#findComment-195227 Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 It will echo <tr> on every third row and in the first row (that's why $i=0, so the first row will get a <tr> too). I mean: 0,3,6,9,12.... Orio. Link to comment https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/#findComment-195254 Share on other sites More sharing options...
pouncer Posted February 27, 2007 Author Share Posted February 27, 2007 ahhhh, i seee! thank you so much Link to comment https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/#findComment-195263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.