View Full Version : Article ordering method

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?

04-03-2007, 10:15 PM
Rewrite the sort order when an aritcle is deleted.

Delete Article id number

Select * from aricles order by sort

update sort = $counter starting a 0

Thats one method.

Or use javascript and ajax to rewrite everything when up press up and down, have it search for the id to update and use some error checking... etc.

Or just rewrite each up and down. I would do it at deletion :)