Jump to content

Multi Level Menu Help


johnrb87

Recommended Posts

Hi all

 

I have a menu function which basically produces a menu which looks like

 

Products
    Apple
       iMac
       iPod
       iPhone
    Microsoft
       Windows
       Office

 

and the code I use is;

 

THE FUNCTION

function menu($parentID, $mymenu)
{
   $html = "";
   if (isset($mymenu['parentID'][$parentID]))
   {
      $html .= "
      <ul>\n";
       foreach ($mymenu['parentID'][$parentID] as $menu_id)
       {
          if(!isset($mymenu['parentID'][$menu_id]))
          {
             $html .= "<li>\n  <a href='/".$mymenu['menu_item'][$menu_id]['url']."'>".$mymenu['menu_item'][$menu_id]['value']."</a>\n</li>";
          }
          if(isset($mymenu['parentID'][$menu_id]))
          {
             $html .= "<li>\n  <a href='/".$mymenu['menu_item'][$menu_id]['url']."'>".$mymenu['menu_item'][$menu_id]['value']."</a>";
             $html .= menu($menu_id, $mymenu);
             $html .= "</li>";
          }
       }
       $html .= "</ul>";
   }
   return $html;
}

 

CREATE MENU CODE

$result = mysql_query("SELECT id, value, url, parentID FROM menu WHERE active = 1 AND deleted = 1 ORDER BY position ASC");
$mymenu = array('menu_item' => array(),'parentID' => array());
while ($menu_item = mysql_fetch_assoc($result))
{
$mymenu['menu_item'][$menu_item['id']] = $menu_item;
$mymenu['parentID'][$menu_item['parentID']][] = $menu_item['id'];
}

echo menu(0, $mymenu);

 

The problem I have is the URLS, at the moment the menu URLS are outputted as

 

Products  -  http://localhost/Products
     Apple  -  http://localhost/Apple
       iMac  -  http://localhost/iMac
       iPod  -  http://localhost/iPod

 

But I need to alter my function so that URLS are outputted as

 

Products  -  http://localhost/Products
     Apple  -  http://localhost/Products/Apple
       iMac  -  http://localhost/Products/Apple/iMac
       iPod  -  http://localhost/Products/Apple/iPod

 

Is this at all possible?

 

Thanks very much everyone

 

John

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.