nested array
| From: | Joris Trooster | Date: | Wed, 21 Feb 2001 21:24:54 +0000 |
| Subject: | nested array | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-180@lists.php.net to get a copy of this message | ||
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:
$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