For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > March 2004 > Re: [SMARTY] this mysql query with smarty









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] this mysql query with smarty
Monte Ohrt

2004-03-19, 1:29 pm

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}&nbsp;{/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.

On Tue, 2004-03-16 at 13:11, dr. zoidberg wrote:
> Hello,
>
> $a = mysql_query("Select a,b FROM t WHERE category=1")
> while($a) {
> $x = $a[a];
> //some echo
> //another query
>
> $b = mysql_query("Select * FROM t WHERE subcategory=$x")
> while ($b) {
> //some echo
> }
> }
>
> Poent is thet I have menus, parents with childes (childes are not
> parents) and I want to display them in smarty like this:
>
> - Parent 1
> -- Child 1
> -- Child 2
> - Patent 2
> -- Child 3
>
> Child have subid that is parent id.
>
> TNX
>
> --
> Please do not CC me.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com