nested sections problem
| From: | Grzegorz Kozioł | Date: | Tue, 19 Mar 2002 02:08:38 +0000 |
| Subject: | nested sections problem | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-3161@lists.php.net to get a copy of this message | ||
Hello
I try to go through mulitidimensional array
in way that manul describe.
this is my code if you could help me I will be grateful :)
example php code
------------------------
$categories =array();
for($i=0; $i <= 3; $i++)
{
$subcategories =array();
for($j=0; $j <= 5; $j++)
{
$subcategories_itm =array ( 'id2' => $j,
'name2' => "item_name".$j
);
array_push($subcategories,$subcategories_itm);
}
$name = "category_name_".$i;
$categories_itm = array ( 'id' => $i,
'name' => $name,
'subcategories' => $subcategories
);
array_push($categories,$categories_itm);
}
$catalog = new Smarty;
$catalog -> assign ("categories",$categories);
$catalog -> display ("catalog.tpl");
example tpl file
-------------------------------
{section name=main loop=$categories}
<li>{$categories[main].id} - {$categories[main].name}</li>
{section name=sub loop=$categories[main].subcategories}
<br>{$subcategories[main].name2} {* number of loops is ok but I can't display
values of subcategories array *}
{/section}
<br>
{/section}
----------------------------------
end of code
this code should work on db and take catalog structure
maincategory - subcategories.
In first for clause - it takes the maincategories
in second - corresponding subcategories by parent id
Best regards
GREGi