Splitting an array into rows
| From: | James Burrows | Date: | Thu, 13 Feb 2003 18:24:53 +0000 |
| Subject: | Splitting an array into rows | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-7738@lists.php.net to get a copy of this message | ||
I have an array, populated in my php script, that I can use in a smarty
template like so: -
{foreach item=game from=$results}
<tr>
<td width="15" valign="top">{$game.pos}<td>
<td valign="top">{$game.name}</a></td>
<td width="40" valign="top>{$game.publisher}</td>
</tr>
{/foreach}
This writes each game item into a row in a table. Now say I want to write 3
games per row (in 3 <td>'s next to each other in the row. If there are any
left over (e.g. if the total number of games is 11 there would be 3 rows of
3 games and 1 row of 2 games).
Is there an easy way in smarty to accomplish this?
Any help would be appreciated!
Cheers,
James