Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    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?

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    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 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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •