I am looking for a script that will allow a user to reorder a list of items that are stored in a MySQL database, preferably by dragging and dropping. I am using php and javascript on the rest of the site. For example, if in MYSQL I use "SELECT rank, title from favoritemovies where user='joe'" to get Rank Title 1 Gone With the Wind 2 Star Wars 3 Mask 4 Flight 5 Skyfall I want the user to be able to drag flight up above Star Wars and update the database so that flight has a rank of 2, Star Wars has a rank of 3, and Mask has a rank of 4. I would prefer not to write from scratch, feel sure the script exists, but can't find it. Any suggestions? Thanks,
Records aren't stored in any order (the order isn't guaranteed), they're retrieved in some order. If you allow the user to change the rank, and update the record with the new date, the next time you retrieve the records - and tell MySQL to ORDER BY Rank ASC - you'll get Flight as the second item with a rank of 2. You can do that in the user's browser by allowing him to drag and drop, and changing the displayed rank as he does, but to get the new rank order the next time, you have to update the ranks in any records that changed in the database. (The easiest way to do that is to just update all displayed records with the displayed rank.)
I ended up using an example I found here http://jsfiddle.net/sidonaldson/PeS2D/ except I changed $(ul) to $("#sortable") and gave my list the id of sortable so that not every list on may page was sortable. Hope that helps somebody.