Re: this mysql query with smarty
| From: | dr. zoidberg | Date: | Tue, 16 Mar 2004 23:36:38 +0000 |
| Subject: | Re: this mysql query with smarty | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11135@lists.php.net to get a copy of this message | ||
Monte Ohrt wrote:
The template only needs to know how to display the items, not what the
parent/child relationship is. So, assign them in the order you want them
displayed, and give each an indent value. Then Smarty just loops through
the values and indents each one.
Something like:
$menu_data = array([0] => array('name' => 'item1', indent => 1),
[1] => array('name' => 'item2', indent => 1),
[2] => array('name' => 'item2.1', indent => 2),
[3] => array('name' => 'item2.2', indent => 2),
[4] => array('name' => 'item3', indent => 1)
[5] => array('name' => 'item3.1', indent => 2),
[6] => array('name' => 'item3.1.1', indent => 3),
);
Then assign & loop over it in the template (untested):
{section name=menu loop=$menu_data}
{section name=foobar
loop=$menu_data[menu].indent} {/section}{$menu_data[menu].name}<br>
{/section}
I'm using {section} as a repeating loop here, This could be simplified
with a block function or modifier.
yes, yes, this might work, but I don't know how to put my data into Array like this.
My database structure is the simpliest one:
+-----+--------+-------+
| id | subid | name |
+-----+--------+-------+
| 1 | 0 | cat |+-----+--------+-------+
| 2 | 0 | cat |+-----+--------+-------+
| 3 | 1 | subcat|+-----+--------+-------+
| 4 | 2 | subcat|+-----+--------+-------+
| 5 | 2 | subcat|+-----+--------+-------+