TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 10-18-2012, 11:14 AM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Oct 2012
Posts: 2
Thanks: 0
soduno is on a distinguished road
Default 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
soduno is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Beginner Guide #1 Hershey Absolute Beginners 1 11-07-2011 10:42 PM
php mysql menu nandananushil1 Advanced PHP Programming 1 11-28-2010 05:09 AM
php drop down menu Shiag Absolute Beginners 2 07-23-2009 10:08 AM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM


All times are GMT. The time now is 11:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design