PHP - Dynamic # Items in Dynamic # Rows = Grid Display

Soldato
Joined
18 Oct 2003
Posts
19,413
Location
Midlands
Right, this will probably be easy logic for some of you, but my mind just isn't comprehending it at the moment.

I've got a dynamic array, anywhere from 0 to 9 items.

I want to display that in a grid, 3x3 depending on how many items there are. So 5 items would be 2 rows, one of 3 and 2 items in the next.

But looping through to achieve this is proving difficult. I think I need to utilise my counter better but if anyone can give a fresh perspective I would much appreciate it.
 

fez

fez

Caporegime
Joined
22 Aug 2008
Posts
25,806
Location
Tunbridge Wells
Use the percentage operator to determine if you are ready for a new row. Check at the end of the looping to clear up any incomplete rows etc.
 
Back
Top Bottom