Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:31

Building a multi-Level menu in PHP


Poster: blaine
Dated: Sunday April 25 2004 - 15:29:36 BST

I have several menu's now being dynamically created by PHP and all is well. Here is my next challenge. I want to be able to create a menu that may be n-levels deep and I won't know if this item has submenu items in advance.

The way I've done this for a top level menu item is to use the
aI("text='.$label.';showmenu=mysubmenu;");

Where submenu1 is a JS function in my menu_data.php which uses PHP to create the menu items. That works well.

Now -- what if the 2nd item of this submenu is another submenu. I can't be creating more JS menu functions in real-time - at least thats not my plan. I need to be able to call a JS function with a parameter like:
aI("text='.$label.';showmenu=mysubmenu(pid);");


The other option I see is being able to generate the needed menu item structure without calling a JS function and generating it all in PHP. This is not a problem for standard menu items - but is for submenus'

Does this make sense - any ideas as I continue to try furhter ?


Poster: blaine
Dated: Sunday April 25 2004 - 18:51:16 BST

Well, I have a working solution that is dymically creating the submenus. I was thinking there may be addmenu type methods but I don't see any in the docs.

If there is a better way - someone please let me know. If not, then maybe this code will help someone else. I place this in my menu_data.php to create a dynamic number of JS functions for the submenus. I then reference them in other code when I am generating the menu - reference these functions.
Code:
<?php
/* Generate the JS Menu Functions that are now needed for each menu item that is a submenu */
$pquery = DB_query("SELECT DISTINCT pid FROM {$_TABLES['glmenu']} WHERE pid > 0");
while (list($pid) = DB_fetchArray($pquery)) {
    echo '
        with(milonic=new menuname("glmenu'.$pid.'")) {
            style=menuStyle1;
            itemwidth="150";
            $query = DB_query("SELECT id,label,url FROM {$_TABLES['glmenu']} WHERE pid='{$pid}' ORDER BY menuorder");
            while (list ($id,$label, $url) = DB_fetchArray($query)) {
                if (DB_count($_TABLES['glmenu'],"pid",$id) > 0 ) {
                   echo 'aI("text='.$label.';showmenu=glmenu'.$id.';");';
                } else {
                    echo 'aI("text='.$label.';url='.$url.';");';
                }
            }
        echo '}';
}
?>

Additional refinements will be made in my final code but this is working.