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

Thread: reorder links

  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post

    reorder links

    I am working on a site where a user can post links to different sites.. I need a way to let users reorder these links that they add... right now if a user wants to reorder their links they have to delete them all and add them on in the order they want them to be in... which obviously isn't very good.. so I need a new way to let users reorder links

    I would like to let users reorder them using a drag and drop interface, but I don't know how to use ajax to make the php calls to save the new spot of the link... I would also like to make sure that users without javascript are taken care of too.. I think the best way to do this is do have a column on the database called ordernumber or something like that... and the order number would change depending on the spot, but I would have to change the order number on everything else.... Any Ideas/suggestions?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Without using Javascript/AJAX the method is a bit clumsy, but works fine. As you mentioned, store a "sort order" integer on each row in your database and then provide "up" and "down" buttons for your users on each and every row of data on your page. Make the buttons so they send the unique ID of the data to your PHP script.

    When the "up" button is pressed, you'll do three queries: The first query gets the sort order number of the row just above the current row, such as SELECT sort_order_nbr, unique_id FROM yourtable WHERE sort_order_nbr < [current sort_order_nr] LIMIT 1. The second query updates this row you just selected with the sort_order_nbr of the current row. The third query updates the current row with the sort_order_nbr from the previous row.

    In other words, you simply SWAP the sort order numbers. Do the same for the down button, only swap sort order with the next row in line.


  •  

    Posting Permissions

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