Working with Multi by Multi levels menu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

Creating a three dimensional menu system is pretty easy with arrays, but
when you want to create a menu system that is 10 or 15 levels deep using
arrays the conventional method is not so simple.

I'm writing an application that shows a multi level (up to 30 levels) menu
which is generated dynamically not in any particular order. There are three
stages:

First stage, generates the levels of the menu and assigns titles,
Second stage needs to come the levels and change its properties, ie icon,
font, colour, etc. This is a critical part of the process as the menus are
not generated in any order and this stage also changes the properties of the
level not in any particular order.
The third stage needs to display this menu.

My search on hotscripts and google didn't turn up anything that's relevant.
I know I can write a recursive function for each of these stages, but thats
not the best method.

This is what I have so far:

for the purpose of this email all menu items are called elements and their
property is an array:

element["parent"] = some other menu element (always an integer) assuming
that 0 is the root
element["title"] = title
element["color"] = etc,etc.

For the first stage:
The first stage assigns the level and the title. A function like
add_element( parentof, $element), function delete_element(parentof,
$element) function move_elelement(newparentof, oldparentof, $element)

to maintain the tracking and consistency each element will be added to the
$v_menu varible as follows:
$c is incremented for each function add_element where a new level exists
$c_child is just a counter of the current element
$v_menu[ $c ]["number of children"] = int
$v_menu[ $c ]["parentof"] = parent of this child, 0 is root.
$v_menu[ $c ][ $c_child ] = $element

second stage
function change_title(parentof, $element)
    this is where I am conteplating ....

third stage
just a recursive function to show it all in order for proper html display. ?

the goal is something like this:

|
|---Menu 1
|        |-------Child of 1
|                   |------------Child of (1, 1)
|                   |                 |-------------------Child of(1,1,1)
|                   |------------Child of (1,1)
|                                    |--------------------Child of (1,1,2)
|                                    |--------------------Child of (1,1,2)
|
|----------------------Child of (1,1,2,2)

Perhaps my approach is wrong on this ? Is there a cleaner method ?

Thanks

Marek

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux