phpchris Posted May 31, 2008 Share Posted May 31, 2008 Hi Anyone, please help! I need help on how to display 3 items in a row and move to next row. I have a short piece of code here and hope someone out there could help me on this.??? ??? <tr> <? $query = "Select * from products"; $result = $db_mysql->query($sql); while ($row = mysql_fetch_row($result)) { for($i=0; i<2; $i++) { ?> <td><? echo $row[id] ?></td> <? } } ?> </tr> The output display is 1 2 3 4 5 but I want it to be displayed like this 1 2 3 4 5 6 7 8 9 10 11 12 I would greatly appreciate if someone could help me on this. THANK YOU! Link to comment https://forums.phpfreaks.com/topic/108123-solved-how-to-display-3-items-in-a-row-and-move-to-next-row/ Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 try this (not tested): <?php <tr> <? $query = "Select * from products"; $result = $db_mysql->query($sql); $count = 0; while ($row = mysql_fetch_row($result)){ if($count % 3 == 2){ //after every third one, php is starting a new line and sets count to 0 again ?> <tr></tr> <?php $count == 0; } ?> <td><?php echo $row[id] ?></td> <?php $count++; } ?> </tr> i have edited a little thing, it should work now! kind regards Link to comment https://forums.phpfreaks.com/topic/108123-solved-how-to-display-3-items-in-a-row-and-move-to-next-row/#findComment-554201 Share on other sites More sharing options...
phpchris Posted May 31, 2008 Author Share Posted May 31, 2008 HI Benedikt, I am able to display 3 items per row and move to next row now. THANK YOU SO MUCH!! You are the best! Regards, chris Link to comment https://forums.phpfreaks.com/topic/108123-solved-how-to-display-3-items-in-a-row-and-move-to-next-row/#findComment-554224 Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 You are welcome. Link to comment https://forums.phpfreaks.com/topic/108123-solved-how-to-display-3-items-in-a-row-and-move-to-next-row/#findComment-554238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.