Page 1 of 1

Storing Hierarchial Menus

Posted: Thu Jan 12, 2006 2:03 pm
by kendall
Hey,

Im building a menu system and im thinking about using the preorder tree traversal algorithm

now usually i'd be using the adjacent model but it gets complicated when having complex depth submenus.

but im having a bit of a task working out the abilities of updating, modifying and adding menu items in relation to sorting records and moving submenus from 1 root menu to the other...

I have the following questions...
  • Would it be a good idea to start each root menu at 1?
  • if i were not to impliment the above idea. what about providing an actual "sort" field. wud this be easier in being able to sort menus and sort thier children using the nested model?
  • im looking at using the nested model system. how easy it is to "move" items from parent to parent using this system. if i took the sort field approach im thinking i can do something php side to work it out.
Kendall

Posted: Fri Jan 13, 2006 6:45 am
by JayBird

hierarchical data database

Posted: Fri Jan 13, 2006 7:29 am
by kendall
Believe it or not...i have been reading through that article as well as a number of other related articles...

the thing is with my situation i am presented with a situation where i think i should have more than one "Tree" structure as would have a situation where i wud have more than one "root" node.

thus its maybe a situation where i should have

menu 1 <- menu with sub menus
12345
menu 2 <- menu with sub menus
12,34,56
menu 3 <- menu
1,2
menu 4 <- menu with sub menus
1,2
menu 5 <- menu with sub menus
12,34,56,78,910

so i want advice on whether this is the approach i shud use or is it like

menu 1 <- menu with sub menus
12,34,56
menu 2 <- menu with sub menus
78,910,1112
menu 3 <- menu
13,14
menu 4 <- menu with sub menus
15,16
menu 5 <- menu with sub menus
1718,1920,2122,2324

Posted: Sun Jan 22, 2006 11:32 am
by thomas777neo
I have a simple yet effective way that I build my menus:

E.g.

Have menu types : heading / sub-heading

Show the headings first:

Menu 1 (heading)

Then in your database have a parent id for the sub heading related to it.

So once the menu is clicked, store the clicked menu somewhere (session, db table)

Then retrieve the sub menu, with the clicked menu.

It should display like this:

<- Menu 1 (clicked menu)
Sub Menu 1

So if you want to return to the top of the menu, simply click on the Menu 1 again.

Or if there is a third level

<- Menu 1
<- Sub Menu 1
Sub Level 3

So you dont even need to display the entire heirarchy at once, but only the selected menus.