I would like my client to be able to order items in the backend. I figured the easiest way to do it is to have the database table for an item have a field called “order” which gets a value. This is a value the client puts in. Then I can just run SQL queries ordering by the “order” field.
Right now I have it very simple.. there is no logic.. so the user would put in order=100 for one item and order=200 for another.. and the one with the lower value would get listed first. Is there a more elegant way of doing this? I am thinking of something like “move up” and “move down”. etc. I am trying to make administrating items more convenient.
Any ideas would be greatly appreciated!
As far as the database goes, your solution using an order field is correct. You probably don’t want to expose this to the user though, and using a pair of up- and down arrows the text input can be circumvented. When a user clicks the ‘up’ arrow, you basically switch the specific record with the record above it. In meta-language:
Note that this is only a very rough draft, you will have to add proper escaping. Also, if you want a UNIQUE index on order to ensure a strict ordering, you will need to change the last two statements.