Dynamic MySQL Nav Menu sorting

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello again,

I have this dynamic menu and I want to change the order of the menu items...
I added a column in the database wich has an integer value for ordering the  
But the only way is by hardcoding them into the database.

I would like a way to sort them with drag-and-drop or with up/down arrows.

Do you think that except PHP & MYsql I will need Javascript as well ?
Any ideas how to do that ?

Thanks a lot,

Re: Dynamic MySQL Nav Menu sorting

for a real drag-and-drop you'll need javascript.

using arrows to move an item up or down can be done with php. the
drawback here would be that every click on an arrow will cause a trip
back to the server to recreate the menu in the new order.

wether to use a javascript or php approach depends on a lot of factors,
to name a few:

- if the sorting is a crucial functionality of your site, don't use
javascript (people might have it disabled or not even visiting with a
- if the new order shall be stored for a certain user, you'll need php
- if speed is a factor, javascript maybe better

i personally would probably use php and not mess around with


Re: Dynamic MySQL Nav Menu sorting

Quoted text here. Click to load it

I do this all the time.

In pseudo code:

    foreach ($menu as $m){
        $uplink = "admin.php?move=$m[id]&to=" ($position-1);
        $downlink = "admin.php?move=$m[id]&to=" ($position+1);

        print "(uplink icon) (downlink icon) row data....<br />";

Then you update the sortorder field when either link is clicked. Remember to  
update the field that it is moved TO so it is moved down/up respectively.

Of course, if the row is the first or the last, you shouldn't have either a  
uplink or downlink.

Plus, if you have a hierarchical menu (like I do), you need to keep track of  
the position number relative to the current hierarchy leve and send that along  
with the query (i.e. move=12&to=3&mother=23)


Re: Dynamic MySQL Nav Menu sorting

 I do this all the time.
Quoted text here. Click to load it
Now we are talking....
Nice One Sandman. ... I'll try that today ;-)  

Site Timeline