We help IT Professionals succeed at work.
Get Started

Smarty: Several foreach loops within loops based on division of a given variable

MaybeItsJeremy
on
471 Views
Last Modified: 2012-05-05
The title probably doesn't make any sense at all, so I'll explain it like this:

I am going to be retrieving entires from my database and I want to format them so only 5 entires can go into each cell. Each row will have two cells, and like I said, 5 entires in each cell.

So, an example of the output would be:

_____________________       _____________________
|         Entry 1               |      |         Entry 6               |
|         Entry 2               |      |         Entry 7               |
|         Entry 3               |      |         Entry 8               |
|         Entry 4               |      |         Entry 9               |
|         Entry 5               |      |         Entry 10             |
_____________________      _____________________

_____________________       _____________________
|         Entry 11              |      |         Entry 16             |
|         Entry 12              |      |         Entry 17             |
|         Entry 13              |      |         Entry 18             |
|         Entry 14              |      |         Entry 19             |
|         Entry 15              |      |         Entry 20             |
_____________________      _____________________

..... etc...

And of course, I need it to show a cell with   if there is an uneven number of cells. And naturally, if the last cell has only say... 3 entires, I don't want the script to mess up... I would just need it to show those 3 if that's all there is.

I would prefer using the foreach Smarty function, rather than section (foreach uses much less code when the template is compiled)

Any help is greatly appreciated! :)
Comment
Watch Question
Top Expert 2005
Commented:
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE