How could i get two records in one iteration of foreach loop using smarty? OR should i use section?
A:
Could you give us the context of your problem? Are your records indexed numerically? A bit of background will help.
thebluefox
2010-04-19 14:40:10
A:
Taken directly from documentation on http://www.smarty.net/manual/en/language.function.section.php#section.property.index.next. Please be sure to read documentation!
{* $rows[row.index] and $rows[row] are identical in meaning *}
<table>
<tr>
<th>index</th><th>id</th>
<th>index_prev</th><th>prev_id</th>
<th>index_next</th><th>next_id</th>
</tr>
{section name=row loop=$rows}
<tr>
<td>{$smarty.section.row.index}</td><td>{$rows[row]}</td>
<td>{$smarty.section.row.index_prev}</td><td>{$rows[row.index_prev]}</td>
<td>{$smarty.section.row.index_next}</td><td>{$rows[row.index_next]}</td>
</tr>
{/section}
</table>
The above example will output a table containing the following:
index id index_prev prev_id index_next next_id
0 1001 -1 1 1002
1 1002 0 1001 2 1003
2 1003 1 1002 3 1004
3 1004 2 1003 4 1005
4 1005 3 1004 5
thetaiko
2010-04-19 14:44:29