Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2013, 12:55 PM   PM User | #1
howard-moore
Regular Coder

 
Join Date: May 2008
Posts: 114
Thanks: 13
Thanked 0 Times in 0 Posts
howard-moore is an unknown quantity at this point
Help with a dynamic drop-menu

Hi,

I have put together the following script which creates a dynamic drop-menu (in unordered list which is subsequently styled in CSS). What I am looking to do is find a way to add a focus to show the menu tab in a different colour when that page has been selected.

The current code is:

Code:
<?php
$result=mysql_query("SELECT id, title, link, parent_code, page_order, menu_title, parent_live, parent_title, page_type, page_admin, live, editable, installed FROM PCNET_$filename WHERE type='PAGE' AND live='checked' ORDER BY parent_code, page_order, title");
$menu = array(
    'items' => array(),
    'parents' => array()
);
while ($items = mysql_fetch_assoc($result))
{
    $menu['items'][$items['id']] = $items;
    $menu['parents'][$items['parent_code']][] = $items['id'];
}
function buildMenu($parent_code, $menu)
{
   $html = "";
   if (isset($menu['parents'][$parent_code]))
   {
      $html .= "\n";
       foreach ($menu['parents'][$parent_code] as $itemId)
       {
          if(!isset($menu['parents'][$itemId]))
          {
             $html .= 	"<li><a href=\"admin_pages_".$menu['items'][$itemId]['link']."?eid=".$menu['items'][$itemId]['id']."\">".$menu['items'][$itemId]['menu_title']."</a></li>";
          }
       $html .= "\n";
          if(isset($menu['parents'][$itemId]))
          {
             $html .= 	"<li><a href=\"admin_pages_".$menu['items'][$itemId]['link']."?eid=".$menu['items'][$itemId]['id']."\">".$menu['items'][$itemId]['menu_title']."</a><ul>";
             $html .= buildMenu($itemId, $menu);
          }
       }
       $html .= "</ul></a></li> \n";
   }
   return $html;
}
echo buildMenu(0, $menu);
?>
All the pages have a unique field which is 'code'. In the past I have used an example of this to add the class 'there' to denote when a page has been selected:

Code:
<li<?php if ($code == 'local-info') echo ' class="there"'; ?>>
However, I cannot see how to add it to my new dynamic menu above. The menu will be called on each page on the site, and each page has the 'code' defined at the top of the script.

I hope someone has any suggestions!

Neil

Last edited by howard-moore; 02-14-2013 at 01:08 PM..
howard-moore is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 PM.


Advertisement
Log in to turn off these ads.