Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Nested Section

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Crazy-
Smarty Rookie


Joined: 12 Oct 2003
Posts: 5

PostPosted: Sun Oct 12, 2003 1:28 pm    Post subject: Nested Section Reply with quote

I'm busy with a howto section on my site with Cats and sub-cats

but now i don't get the subcats under de cats:

[php:1:f9f6ce128d]$DB->uitvoeren("SELECT * FROM howtos_cats");
while($howtos_cats_array = $DB->uitlezen()) {

$cats[] = array(
'cat_naam' => $howtos_cats_array['cat_naam'],
'cat_pic' => "/images/howtos/".$howtos_cats_array['pic'],
);

// haal de subcats eruit
$DB2->uitvoeren("SELECT * FROM howtos_sub_cats WHERE cat_id = $howtos_cats_array[id]");
while($howtos_subcats_array = $DB2->uitlezen()) {

$sub_cats[] = array(
'sub_naam' => $howtos_subcats_array['sub_naam'],
);
}
}

// maak het klaar voor de template
$so->assign("cats",$cats);
$so->assign("sub_cats",$sub_cats);[/php:1:f9f6ce128d]

and the template

Code:
{section name=cat loop=$cats start=1}
 {$cats[cat].cat_naam}

   {section name=subcat loop=$sub_cats[cat]}
     {$sub_cats[cat][subcat].sub_naam}
   {/section}

{/section}


could somebody help me?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Oct 12, 2003 2:23 pm    Post subject: Reply with quote

{section} is for indexed arrays. You want {foreach} which works with associative arrays.
Back to top
View user's profile Send private message
Crazy-
Smarty Rookie


Joined: 12 Oct 2003
Posts: 5

PostPosted: Sun Oct 12, 2003 3:26 pm    Post subject: Reply with quote

can you explain it a little bit ?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Oct 12, 2003 4:10 pm    Post subject: Reply with quote

I think my reply was hasty Smile

it looks like your subcats is not 2 dimensional. perhaps something like this

$sub_cats[$i][] = array( 'sub_naam' => $howtos_subcats_array['sub_naam']);

and $i starts at 0 and is incremented for each new cat
Back to top
View user's profile Send private message
Crazy-
Smarty Rookie


Joined: 12 Oct 2003
Posts: 5

PostPosted: Sun Oct 12, 2003 4:23 pm    Post subject: Reply with quote

Rolling Eyes stupid me !

you're right Smile

thnx a lot
Back to top
View user's profile Send private message
Crazy-
Smarty Rookie


Joined: 12 Oct 2003
Posts: 5

PostPosted: Mon Oct 13, 2003 11:36 am    Post subject: Reply with quote

hm, when i put a howto under a subcat, the ID is +1

so:

howto: subcat_id = 1

then it is showed under sucat_id 2 !

Code:
{section name=cat loop=$cats start=1}
  {$cats[cat].cat_naam}

  {section name=subcat loop=$sub_cats[cat]}
    {$sub_cats[cat][subcat].sub_naam}

      {section name=howtos loop=$howtos[cat][subcat]}
        {$howtos[cat][subcat][howtos].howto_titel}
      {/section}

  {/section}

{/section}
Back to top
View user's profile Send private message
Crazy-
Smarty Rookie


Joined: 12 Oct 2003
Posts: 5

PostPosted: Tue Oct 14, 2003 8:19 am    Post subject: Reply with quote

somebody?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP