04-03-2007, 09:11 PM
We have an ordering method for our articles that allows our users to change the order they appear on the news page. I simply created an "arrangement" column in the articles table, and it keeps the order number for each article. I went through each article and set a number to it, and then on the admin page, the user can click the up or down arrow to change the order. For instance, if the user clicks the up arrow, the PHP code takes the current order number of the article, subtracts 1 from it, writes that to the DB, then gets the article with that order number, adds 1 to it, then writes it. It works great, but I ran into a problem. If a user deletes an article in the middle (let's say article 5 of 10), as you can guess, there is now a gap in the order. So if the user tries to move the article with order number 6 up, it won't move because it just gets written to 5. So how exactly should I make sure there are no gaps in the order numbers?