Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    May 2008
    Thanked 0 Times in 0 Posts

    Help with a dynamic drop-menu


    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:

    $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)
                 $html .= 	"<li><a href=\"admin_pages_".$menu['items'][$itemId]['link']."?eid=".$menu['items'][$itemId]['id']."\">".$menu['items'][$itemId]['menu_title']."</a></li>";
           $html .= "\n";
                 $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:

    <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!

    Last edited by howard-moore; 02-14-2013 at 02:08 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts