Re: nested array

From: Date: Fri, 23 Feb 2001 14:53:16 +0000
Subject: Re: nested array
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-200@lists.php.net to get a copy of this message
On Wed, 21 Feb 2001, Joris Trooster wrote: > An example: > > $db_result = new DB_sql( "SELECT * FROM countries"); > while( $db_result->next_record() ) { > $countries[] = $db_result->Record; > $countries[]["states"] = > get_state_array_from_db($countries["country_name"]) > } > $smarty->assign( "countries" , $countries); > > And in the template: > > {section name=co_list loop=$countries} > {$co_list/countries.country_name} > {section name=st_list loop=$co_list/countries.states} > {$st_list/co_list/countries.states.state_name} > {/section} > {/section} > > However this does NOT work. The following works: No, it won't work. Smarty first indexes by the section counter and then by the associative keys, so in the compiled version the inner variable access will look something like this: $countries[$st_list][$co_list]['states']['state_name'] Plus, you should always index from outer to inner, i.e. $co_list/st_list/countries and not $st_list/co_list/countries. -Andrei "In My Egotistical Opinion, most people's C programs should be indented six feet downward and covered with dirt." -- Blair P. Houghton

« previous php.smarty.general (#200) next »