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

    How to make the parent menu get selected in multi level menu?

    How to make the parent menu get selected in multi level menu.

    For example we have following multilevel menu:

    Menu1
    Menu2
    - Menu2.1
    - Menu2.2
    -- Menu2.2.1
    -- Menu2.2.2
    Menu3
    -Menu3.1

    I generated the above menus from db table of following structure
    id | parent_id|title
    using recursive method.


    I would like to know the logic of how to put some class(say class="active") in the parent level

    menus if its child is selected
    For example if Menu2.1 or Menu2.2.1 or any child menus is clicked then Menu2 should be selected.
    if Menu3.1 is clicked then Menu3 should be selected.
    (Note: the page is reloaded when clicked on the menu links)

    Thanks in advance for any valueable suggestions/hints/logic.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    $menu['id'] = $_GET['selectedMenu'];
    do {
    $query mysql_query Get the parent id from the database for $menu['id'] );
    $menu mysql_fetc_array($query);
    } while ( 
    $menu['parentid'] != ); 
    That should get the top menu


  •  

    Posting Permissions

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