Re: [SMARTY] problem to view double array
| From: | Monte Ohrt | Date: | Wed, 19 Nov 2003 15:44:38 +0000 |
| Subject: | Re: [SMARTY] problem to view double array | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-10551@lists.php.net to get a copy of this message | ||
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