Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: reorder links
11-04-2010, 01:49 AM #1
- Join Date
- Jul 2009
- Thanked 1 Time in 1 Post
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
11-05-2010, 01:47 AM #2
- Join Date
- Dec 2005
- Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
- Thanked 637 Times in 625 Posts
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.