Storing sort order in mySQL
Posted: Thu Mar 09, 2017 10:36 pm
I have done some research into this, and settled on 2 options, maybe someone here has a better 3rd option for me.
pretend we have a table like this
Priority | Itemnumber
100000 | Item 1
200000 | Item 2
300000 | Item 3
Now we want to move Item 3 between item 1 and 2
Option 1
This option is limited to how many times you can re-prioritize.
get the next 2 lower priority numbers of item 3 and add them together and then divide by 2 getting 150000
set priority of Item 3 to 150000
Option 2
This option takes one more query
get the next lower priority of Item 3
set the priority of Item 3 to 200000
set the priority of Item 2 to 300000
Is there a better Option 3?
pretend we have a table like this
Priority | Itemnumber
100000 | Item 1
200000 | Item 2
300000 | Item 3
Now we want to move Item 3 between item 1 and 2
Option 1
This option is limited to how many times you can re-prioritize.
get the next 2 lower priority numbers of item 3 and add them together and then divide by 2 getting 150000
set priority of Item 3 to 150000
Option 2
This option takes one more query
get the next lower priority of Item 3
set the priority of Item 3 to 200000
set the priority of Item 2 to 300000
Is there a better Option 3?