...

View Full Version : How to make the parent menu get selected in multi level menu?



PHPycho
08-23-2009, 01:20 PM
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.

Mwnciau
08-23-2009, 01:41 PM
$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'] != 0 );

That should get the top menu



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum