Re: nested array

From: Date: Thu, 22 Feb 2001 16:04:19 +0000
Subject: Re: nested array
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-195@lists.php.net to get a copy of this message
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"]) > } Right here, do var_dump($countries) This will most likely show you your problem. > $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: > > $db_result = new DB_sql( "SELECT * FROM countries"); > while( $db_result->next_record() ) { > $countries[] = $db_result->Record; > $states[] = get_state_array_from_db($countries["country_name"]) > } > $smarty->assign( "countries" , $countries ); > $smarty->assign( "states" , $states ); > > And in the template: > > {section name=co_list loop=$countries} > {$co_list/countries.country_name} > {section name=st_list loop=$co_list/states} > {$st_list/co_list/states.state_name} > {/section} > {/section} > > What I tried to do in the first example was to assign one nested array to > Smarty. I thought it was pretty straightforward. Did I overlook something or > is Smarty the limitation? > > Joris > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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