Reputation: 4300
I have a int(11) DisplayOrder
column in my database of slideshow items which tells my code what order to display the items in. An admin can update the order with a form, changing, for example, number 20 to number 3. Without forcing the user to manually find number 3 and swap it with 20, is there an easy way to update the sequence of numbers in the database? Either using MySQL, or changing items in in array()
before sending a query.
I've searched and searched, and there doesn't seem to be many solid answers. The issue is that I currently have 400 rows, and that number will grow. I don't really want to have to do 400 updates every time the order changes. Is there a better way? Are there existing scripts?
Upvotes: 0
Views: 1481
Reputation: 611
Why do you need to fully resequence the DisplayOrder
values?
An ORDER BY
clause will work just as well if there are duplicate values. To maintain a stable sort, you can order by a secondary column such as item name or id.
Upvotes: 2