|
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 |
plungerman Smarty n00b
Joined: 23 Jul 2003 Posts: 2
|
Posted: Wed Jul 23, 2003 9:40 pm Post subject: Using the same associative array twice with foreach |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 23, 2003 9:55 pm Post subject: |
|
|
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 |
|
plungerman Smarty n00b
Joined: 23 Jul 2003 Posts: 2
|
Posted: Thu Jul 24, 2003 12:20 pm Post subject: |
|
|
thanks boots. your solution worked perfectly. |
|
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
|