As for the database, your decision using the order field is correct. You probably don't want to show this to the user, and using a couple of up and down arrows, you can turn off text input. When the user clicks the up arrow, you basically switch the specific record with the record above it. In metalanguage:
// $myId holds id of record, $myOrder holds the order of the record
SELECT id, order FROM t WHERE order < $myOrder LIMIT 1
// Store id in $nextId, order in $nextOrder
UPDATE t SET order = $nextOrder WHERE id = $myId
UPDATE t SET order = $myOrder WHERE id = $nextId
Please note that this is just a rough draft; you will need to add the correct escaping. In addition, if you need a UNIQUE index to ensure strict ordering, you will need to modify the last two statements.
source
share