Re: SV: [SMARTY] problem to view double array
| From: | Monte Ohrt | Date: | Wed, 19 Nov 2003 17:55:37 +0000 |
| Subject: | Re: SV: [SMARTY] problem to view double array | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-10552@lists.php.net to get a copy of this message | ||
I'll try.
$smarty->assign('mythings' => array(
0 => array('name' => 'thing1', 'depth' => 0),
1 => array('name' => 'thing2', 'depth' => 1),
2 => array('name' => 'thing3', 'depth' => 2),
3 => array('name' => 'thing4', 'depth' => 1)));
In the template:
{foreach from=$mythings item=currthing}
{section name=repeat loop=$currthing.depth}-{/section}>{$currthing.name}
{/foreach}
The output should be something like:
>thing1
->thing2
-->thing3
->thing4
Notice I'm using a section loop to output the depth. I suppose Smarty
should have a {repeat} function to make this cleaner. :)
Monte
On Wed, 2003-11-19 at 11:39, JohannesF - Poeter.se wrote:
> Hi and thank you for the awnser Monte, Im not sure I follow you...
>
> Is it possible for you to post an example??
>
> thanks again // JohannesF
>
>
>
> -----Ursprungligt meddelande-----
> Från: Monte Ohrt [mailto:monte@ispi.net]
> Skickat: den 19 november 2003 16:45
> Till: JohannesF - Poeter.se
> Kopia: Smarty General
> Ãmne: Re: [SMARTY] problem to view double array
>
>
> Put your items in one array and give each one a corresponding level.
> Then depending on the level, intent your text over. This way there is
> one foreach loop (no nesting) and you can go any level deep.
>
> Monte
>
> On Wed, 2003-11-19 at 04:50, JohannesF - Poeter.se wrote:
> > Hi list
> >
> > I have problem to view this page, and I cant get it to work. Please, can
> > anyone on the list help me to solve the problem? This is the way I want it
> > too look. Have been strugeling too long now.... Grrrr!! Sorry for bad
> > spelling :-) To generate the sql I use ADOdb. Thank you!
> >
> > texthead
> > texthead
> > - messhead
> > - messhead
> > texthead
> > - messhead
> >
> > load-file.php
> > ------------------------------------
> >
> > $sql = "[sql]";
> >
> > $result = $db->Execute($sql);
> >
> > $items = array ();
> >
> > while (!$result->EOF){
> > $item = array ();
> > $item['texthead'] = $result->fields['texthead'];
> > $items[] = $item;
> > $lastone = $result->fields['textid'];
> >
> > //level two
> > $sql2 = "select messhead from junior_mess where textid=$lastone";
> > $result2 = $db->Execute($sql2);
> > $items2[$lastone] = array();
> > while (!$result2->EOF){
> > $items2[$lastone][] =
> > array('messhead'=>$result2->fields['messhead']);
> > $result2->MoveNext();
> > }
> > $result->MoveNext();
> > }
> >
> > $smarty->assign("items", $items);
> > $smarty->assign("items2", $items2);
> >
> >
> > and here the template, tpl-file.tpl
> > ----------------------------------------------------
> > {foreach from=$items key=one_id item=levelone}
> > {$levelone.texthead}<br>
> >
> > {foreach from=$items2[$one_id] item=leveltwo}
> > {$leveltwo.messhead}<br>
> > {/foreach}
> >
> > {/foreach}
> > ----------------------------------------------------
> >
> >
> >
> > thanks alot! / JohannesF
> >
> >
> >
> > -----------------------------
> > Johannes Fosseus
>