Incremental Update: Re-ordering Menu Structure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

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:

Incremental Update: Re-ordering Menu Structure

Post by kendall »

hello,

im building a dynamic menu structure in which has submenus and want to be able to effeciently impliment a re-ordering system based on user selection.
i have the following menu structure

Code: Select all

ID | menu | group | parent | order
43981 | Client Success | Success  |0  |1  
7000 | Services |  Services  |0  |  2
4000|  About Us  | About  | 0 | 3 
4001  |  Who We Are  |  About  | 4000 |4 
4002  |  Strategic Partners | About  |4000  |5  
4003  |  Contact Us  | About  | 4000 |6
Now lets use an e.g. to explain what i want to accomplish...
lets say i want to move 4002 from position 5 to 4
pretty easy
  • First i update the menus between 4 and 5
  • Then i update 4002 to 4
but lets say i want to move menu 4000 to 1
  • First i update the menus between 2 and 3
  • Then i update 4000 to 1
  • Then update menus to 1+(i++) who is child of 4000
So...I run into the following problems
Updating menus position based on thier submenus if any
How can i generate the (i++) on each row update
Any suggestions of improving this theory?

Kendall
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Since there are only a small number of items, it might make sense to load them all, make the changes and the update them all. That way the whole list is atomic. I doubt it will be updated often.
(#10850)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

This sitepoint article may be of interest....

Storing Hierarchical Data in a Database
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

CodeGoblin,

Yeah i knew about that. I was trying it out for a while and found the updating part a bit tedious so i opted for the solution i was trying out now...apparantly i didnt realise that my method is even more tedious and cumbersome. oh well back to the drawing board
Post Reply