slyte33 Posted December 1, 2009 Share Posted December 1, 2009 Hi, what i'm trying to figure out what to do, after googling and no answers, is for every 5 rows, i'd like to start a new row in a table. Short Example: echo "<table><tr>"; select * from example while loop { for every 5: echo "<tr>"; echo "<td>"; echo "example, this line will show 5 times per row, without having to do 'limit 5' in every query"; echo "</td>"; echo "</tr>"; } echo "</table>"; I hope that explains it. Thanks Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/ Share on other sites More sharing options...
mrMarcus Posted December 1, 2009 Share Posted December 1, 2009 just add an incremental value in there, and an IF statement to handle things when the value is reached: echo "<table><tr>"; select * from example $i = 1; while loop { //for every 5: echo "<td>"; echo "example, this line will show 5 times per row, without having to do 'limit 5' in every query"; echo "</td>"; if ($i == 5): echo '</tr><tr>'; endif; $i++; } echo "</tr></table>"; something very, very basic, but that should give you something to play with. Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/#findComment-969057 Share on other sites More sharing options...
slyte33 Posted December 1, 2009 Author Share Posted December 1, 2009 just add an incremental value in there, and an IF statement to handle things when the value is reached: echo "<table><tr>"; select * from example $i = 1; while loop { //for every 5: echo "<td>"; echo "example, this line will show 5 times per row, without having to do 'limit 5' in every query"; echo "</td>"; if ($i == 5): echo '</tr><tr>'; endif; $i++; } echo "</tr></table>"; something very, very basic, but that should give you something to play with. I tried it, but it only does it one time. Should I just do this: if ($i == 5): echo '</tr><tr>'; endif; if ($i == 10): echo '</tr><tr>'; endif; if ($i == 15): echo '</tr><tr>'; endif; if ($i == 20): echo '</tr><tr>'; endif; ...and so on? I only ask because I only need to use about 100 rows. Thanks for the feedback Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/#findComment-969063 Share on other sites More sharing options...
aeroswat Posted December 1, 2009 Share Posted December 1, 2009 just add an incremental value in there, and an IF statement to handle things when the value is reached: echo "<table><tr>"; select * from example $i = 1; while loop { //for every 5: echo "<td>"; echo "example, this line will show 5 times per row, without having to do 'limit 5' in every query"; echo "</td>"; if ($i == 5): echo '</tr><tr>'; endif; $i++; } echo "</tr></table>"; something very, very basic, but that should give you something to play with. I don't think this will work will it? My expertise isn't php but my advice would be to increment the counter variable like he is doing in a loop and instead of putting the part where he has: if($i==5) put a mod operator if($i%5==0) Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/#findComment-969064 Share on other sites More sharing options...
kickstart Posted December 1, 2009 Share Posted December 1, 2009 Hi I would be tempted to use something like this, using mod (ie, %) to check whether it is the fifth row or not. echo "<table><tr>"; select * from example $i = 1; while loop { if (($i % 5) == 0) { echo "<tr>"; echo "<td>"; echo "example, this line will show 5 times per row, without having to do 'limit 5' in every query"; echo "</td>"; echo "</tr>"; } $i++; } echo "</table>"; All the best Keith Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/#findComment-969065 Share on other sites More sharing options...
slyte33 Posted December 1, 2009 Author Share Posted December 1, 2009 Works great, thanks everyone ! Link to comment https://forums.phpfreaks.com/topic/183597-for-every-5-rows-use-in-table/#findComment-969075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.