What is the best way to assign orders to mysql table rows? If I have rows 1 to 5 and I want to remove 4, how can I make 5 the new 4? If I make make 3 the new 1, I need to add 1 to each of the other rows. There could be 1 or 2 rows or a hundred.
Is there a simpler way than manually programming each contingency?
Thanks in advance.
additional:
I have an interface where I add packages for customers to see. They are automatically ordered ascending by id. I can reorder them by price, package name, or whatever, but I want to arbitrarily order them by my own preference from time to time.
Thanks again.
Assuming you have a unique
order_columncolumn in your database:To add a new row at position x:
To swap positions x and y:
UPDATE table SET x=(@temp:=x), x = y, y = @temp;(source)
To remove a row at position x:
To display data:
Just
ORDER BYby theorder_columncolumn.