Storing Hierarchial Menus

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Storing Hierarchial Menus

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

hierarchical data database

Post 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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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.
Post Reply