Dynamic menu ordering

For a dynamic menu I’m building, I need to be able to shift menu items up or down instead of just order it by the ID in my SQL table. I’ve added a new column to the menuTable calles menuRank. But now I can’t seem to get my mind around the right queries to give the records the right ranking. Naturally they should be uniquely numbered 1 through well… the amount of rows available :wink: Now, that I can do with new records (take the record with the highest ranking and add 1), but as I’ve added the ranking column after already working with the menuTable, I’ve given them a ranking equals to the ID, with leaves me with holes. (1 2 3 4 5 7, where’s 6?). I do believe I can fix that to get things started by writing a loop, so that too is no problem. But then the hard part begins: swapping/shifting rankings. By changing 1 row (ranking it 1 up or 1 down), the entire table would need an update, either adding or subtracting ‘1’ from the rows current ranking, dependent on the record that has just been changed through my sites backend.

Trying and thinking has already cost me near to a week :hangover: and searching online hasn’t helped much either, so now I put my questions to you, people with more knowledge and experience :wink: Teach me! :wink:

And again, thank you in advance :slight_smile: