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

Using the same associative array twice with foreach

 
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
plungerman
Smarty n00b


Joined: 23 Jul 2003
Posts: 2

PostPosted: Wed Jul 23, 2003 9:40 pm    Post subject: Using the same associative array twice with foreach Reply with quote

hello,

i want to use the same associative array twice, which i have assigned from the parent php page and which i access in the template using foreach. here's the example:

{foreach item="country" from=$country}
{if $advert.client_address_country_id.val==$country.id}
{$country.name}<br />
{/if}
{/foreach}

and later on in the template:

<select name="orders_billing_country_id">
{foreach item="country" from=$country}
{if $advert.orders_billing_country_id.val==$country.id}
<option value="{$country.id}" selected> {$country.name}
{else}
<option value="{$country.id}"> {$country.name}
{/if}
{/foreach}
</select>

the problem is that the associative array seems to be inaccessible after the first time you loop through it. the select statement above does not contain any of the values from the array. if i delete the first foreach loop, then the second one works just fine. strange eh?

anyone seen this before? shed some light?

thanks,

steve
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Jul 23, 2003 9:55 pm    Post subject: Reply with quote

Not so strange. Because you are using "country" as the item for the first foreach which causes the $country var to be overwritten. Use something else, perhaps by calling the list of countries $countries.
Back to top
View user's profile Send private message
plungerman
Smarty n00b


Joined: 23 Jul 2003
Posts: 2

PostPosted: Thu Jul 24, 2003 12:20 pm    Post subject: Reply with quote

thanks boots. your solution worked perfectly.
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