Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Nested menus from 3 tables

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Putri
Smarty n00b


Joined: 07 Feb 2012
Posts: 1

PostPosted: Tue Feb 07, 2012 5:21 am    Post subject: Nested menus from 3 tables Reply with quote

Hello,
Can someone please explain how to query the database to use this smarty code to create nested menus from 3 tables:
Code:

{* define the function *}
{function name=menu level=0}
  <ul class="level{$level}">
  {foreach $data as $entry}
    {if is_array($entry)}
      <li>{$entry@key}</li>
      {menu data=$entry level=$level+1}
    {else}
      <li>{$entry}</li>
    {/if}
  {/foreach}
  </ul>
{/function}

{* create an array to demonstrate *}
{$menu = ['item1','item2','item3' => ['item3-1','item3-2','item3-3' =>
['item3-3-1','item3-3-2']],'item4']}

{* run the array through the function *}
{menu data=$menu}

I use the following SQL code:
Code:

SELECT level0.description,level1.description,level2.description
FROM level0
LEFT JOIN level1
ON level0.id=level1.parentid
LEFT JOIN level2
ON level1.id=level2.parentid


How to put the results as an array like in sample $menu array using php?
Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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