Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Article ordering method
04-03-2007, 08:11 PM #1
- Join Date
- Nov 2006
- Thanked 18 Times in 18 Posts
Article ordering method
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, 09:15 PM #2
- Join Date
- Oct 2005
- Right Here
- Thanked 0 Times in 0 Posts
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 just rewrite each up and down. I would do it at deletion