|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
traveler Smarty n00b
Joined: 14 Jul 2003 Posts: 2
|
Posted: Mon Jul 14, 2003 11:17 pm Post subject: foreach loop question, urgent. many thanks |
|
|
Hi,
I am new to smarty. can anyone point out what's wrong here? I got nothing. Is there an alternative way?
in tpl file:
{* Smarty *}
<table>
{foreach name=outer item=category from=$rowArray}
<tr> <td>category address: {$category.address}</td>
<td>category city: {$category.city} </td>
</tr>
{foreach name=inner item=house from=$houseArray}
{foreach name=inner2 item=single from=$house}
<tr> <td>name: {$single.address}</td>
<td>home: {$single.city}</td>
</tr>
{/foreach}
{/foreach}
{/if}
{/foreach}
</table>
in php file:
for($catNum=0; $catNum<4; $catNum++)
{
for ( $houseNum=0; $houseNum<5; $houseNum++)
{
if ( $houseNum == 0 )
{
$category[$catNum]["address"] = "ADDRESS0";
$category[$catNum]["city"] = "CITY0";
} else
{
$house[$catNum][$houseNum] = array('address'=>'address1', 'city'=>'city1');
}
}
}
$smarty->assign("houseArray", array($house[0], $house[1], $house[2], $house[3] );
$smarty->assign("rowArray", array($category[0], $category[1], $category[2], $category[3]) );
I am expecting to have a display sth like:
ADDRESS0 CITY0
address1 city1
address1 city1
ADDRESS0 CITY0
address1 city1
address1 city1
...
...
many thanks. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 16, 2003 8:53 am Post subject: |
|
|
Hmm. One obvious thing is that unmatched {/if} in your template.
Out of curiousity, what results are you getting? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|