Instead of adding the weight column to the MYSQL table, add the next_object column to the table.
It will function as a linked list (if you are familiar with this). Each entered object points to the next object.
Go through the script to move the object of position 90 to position 10.
First you need to update the 89th object so that it now points to the 91st object (new 90th object)
Then you need to update the 9th object and point it to the 90th object (new 10th object)
Finally, you need to update the 90th object (new 10th object) and point it to the 10th object (new 11th object)
And, of course, I want to say that I update the next_object field to the object I'm talking about.
What exactly could you put as the value in the next_object field? Just an object identifier or something like that.
I just came up with this system as an alternative when I started writing this answer, so I'm not sure if this is the most efficient way. But hey, updating 3 objects is better than the potential 100,000 (if you had 100,000 objects).
source share