TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Multilevel php menu (http://www.talkphp.com/general/6479-multilevel-php-menu.html)

soduno 10-18-2012 11:14 AM

Multilevel php menu
 
Hello.

I'm trying to make an multilevel menu. But the way i wan't it to work seems to be a bit complicated for me. I wan't the menu to work like this one(left menu): http://www.proconsult.dk/. The page must reload every time a menu has been clicked, because i wan't a new page to open (newest offers related to the clicked category).

So far i managed to get a non collapsable menu script:
PHP Code:

<?php 
// get all menuitems with 1 query 
$result mysql_query("SELECT cat_id, cat_parent, cat_name FROM categories ORDER BY cat_id, cat_name ");

// prepare special array with parent-child relations 
$menuData = array( 
    
'items' => array(), 
    
'parents' => array() 
); 

while (
$menuItem mysql_fetch_assoc($result)) 

    
$menuData['items'][$menuItem['cat_id']] = $menuItem
    
$menuData['parents'][$menuItem['cat_parent']][] = $menuItem['cat_id']; 


// menu builder function, parentId 0 is the root 
function buildMenu($parentId$menuData

    
$html ''

    if (isset(
$menuData['parents'][$parentId])) 
    { 
        
$html '<ul>'
        foreach (
$menuData['parents'][$parentId] as $itemId
        { 
            
$html .= '<li>' $menuData['items'][$itemId]['cat_name']; 

            
// find childitems recursively 
            
$html .= buildMenu($itemId$menuData); 

            
$html .= '</li>'
        } 
        
$html .= '</ul>'
    } 

    return 
$html


// output the menu 
echo buildMenu(0$menuData);
?>

Just so you know. I don't want to use any Jquery, the menu must be pure php, if possible :-)
Thank you in advance.

Regards, Simon

shui1880 11-13-2012 11:37 AM

If you are a music enthusiast longing to listen to your favorite music for extended periods of time, Monster headphones fit the bill perfectly. They have been designed to ensure a thrilling music experience for extended periods without causing discomfort or pain to the user. An interesting feature of Dr Dre Headphones the Monster Beats is that you don need to dig into your pocket to pause or press mute. A quick tap is what it takes to do the needful. You can choose from a variety of eye-catching accessories to complement dr dre beats these headphones. Browse the web to navigate an exotic range of stunning accessories online. They are http://www.drdreheadphones-sale.net available at astonishingly competitive prices.


All times are GMT. The time now is 11:20 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0