Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

foreach loop question, urgent. many thanks

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
traveler
Smarty n00b


Joined: 14 Jul 2003
Posts: 2

PostPosted: Mon Jul 14, 2003 11:17 pm    Post subject: foreach loop question, urgent. many thanks Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 8:53 am    Post subject: Reply with quote

Hmm. One obvious thing is that unmatched {/if} in your template.

Out of curiousity, what results are you getting?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP