TwelvestoneBack End

Rearrange Navigation Menu


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Suzy
 
2010-07-07

Hi guys, Can I just ask a bit of advice please. I have a navigation menu held in a database where the user can add, remove or edit menu items via an admin system I've created. They can currently order it alphabetically or by date added but they want to be able to order it however they want. What logic would I use to achieve this? Thanks, Suzy ?

DontBogartMe
 
2010-07-07

I would have an extra column in your db table that stores a number to order the items by. Call it "menu_order" or something, so as not to clash with the reserved word "order". e.g. id menu_name menu_order 1 apple 2 2 banana 1 3 orange 3

Note that it is NOT the same as the unique ID column number.

When you show the menu you pull out the rows ordered by menu_order. So using the data above you'd get: banana apple orange

In your admin interface if they choose "order alphabetically" then you run through the table and update that menu_order column so that it matches the alphabetical order:

id menu_name menu_order 1 apple 1 2 banana 2 3 orange 3

Or you can let them move the items around - you just have to keep updating the menu_order values so the order they choose is stored.

Make sure you keep the menu_order numbers unique in that table - you can't have two items with the order number 2 for instance.

Suzy
 
2010-07-07

Cheers DBM k

So in that logic would I be better off having in my admin system a number against each menu item that shows what place it is in the list so if they change place 3 to place 2 they will then need to change all the other numbers too and I do a check to make sure no number is duplicated.

Or is there an easier way for them to rearrange the menu order?

Suzy
 
2010-07-07

Just found thishttp://www.siteexperts.com/tips/elements/ts32/page1.asp Would I be better off trying to work with that?

DontBogartMe
 
2010-07-07

Originally posted by: Suzy Just found thishttp://www.siteexperts.com/tips/elements/ts32/page1.asp Would I be better off trying to work with that?

that's pretty much using the method I mentioned.. although it's not saving to any database.

Originally posted by: Suzy So in that logic would I be better off having in my admin system a number against each menu item that shows what place it is in the list so if they change place 3 to place 2 they will then need to change all the other numbers too and I do a check to make sure no number is duplicated.

I would advise against asking the user to type the order number in - they'll never get it right. You should hide the order number from them, update it behind the scenes. The technique in that tutorial you posted is fine - i.e. the user selects an item to move, then hits UP or DOWN to move it - your code moves it and changes the order numbers.

DontBogartMe
 
2010-07-07

also, remember when you move an item up or down, you don't need to change all the numbers in the list, you just need to swap the two that are moving. e.g. if you move it UP, you swap the item's order num with the order num of the item above it. When you add a new item to the list you just give it an order num that is 1 higher than the previous highest one (or list length plus one). If you delete an item from the list, then yeah, you need to change the numbers of all the items after the one you deleted.

Suzy
 
2010-07-07

Thanks DBM k I'm only quoting for this at the moment so you will see lots of questions for this in about 3 months time k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Rearrange Navigation Menu