PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating Sortable Lists With PHP And Ajax

Article Comments (18 total)

Displaying article comments 11 to 18 of 18
Nguni, 19 April 2007
Hi, I love this post. I learned a lot from it and I used some of the code to make my own sortable lists, and was dragging between lists. However, if I want to update between lists, I don't know which list is being updated, so that function processOrders doesn't work so well. It works perfectly here becauase you know the name of the array, 'movie_list', since you have only one list. With more than one list, the name of the list currently being updated is unknown, so how would you call that function processOrders() from processor.php? Thank you, Nguni Phakela

Paul G, 16 April 2007
I think this is stunningly, amazingly Cool Web Stuff. I had no trouble getting it to work, and I am way down the learning curve! The only catch is, I would like to modify it to work on a subset of data. For example, what if we added a column to the movies list which indicated the genre of movie (e.g. drama, comedy, etc.). Then I'd like to call index.php?genre=4 and see and be able to sort only the items in genre 4. I have fiddled and fiddled, and I can't figure out how to do this. It seems to me you need the ability to pass a parameter to the onUpdate handler; I'm not sure if that can be done, or how to do it. If anyone can point me towards discussions on furthering this technique, I'd sure appreciate it. When I try to read the official docs for any length, my eyes glaze over and I have an urge to begin using MSIE :) Thanks

Mark Warner, 12 April 2007
Great tutorial! In the "processMoviesOrder" function, I want the "movie_id" column to be a variable so I can update other columns based on similar situations. For instance, I'm trying this method to determine the running order of a photo gallery. Some of the photos are also in a "latest" section so I want "movie_id" to be "latest_id" when I'm editing my "Latest" list. Any recommendations? Many thanks. Mark

niko, 11 April 2007
hi..thanks for the tutorial it helped me...but i wanted to know is it possible to implement the same using div tag which may help to build photo gallery for rearrangement

Ramsundar, 11 April 2007
Hi, Is this sorting possible only with a or can it be customized for a , tr, td. Please advise me

oblius, 26 January 2007
There is an error in the updateOrder() function. The options object should use 'postBody', not 'parameters', to pass Sortable.serialize('movies_list') [code] var options = { method : 'post', [b]postBody[/b] : Sortable.serialize('movies_list') }; [/code]

Null, 5 January 2007
I don't wanna ajax this, i want to manual update the database using an submit button. How to do this? Thx

Chris Bugert, 27 July 2006
In processMoviesOrder() it appears as though this line: if (!array_key_exists($movie_id, $movies)) should be: if (array_key_exists($movie_id, $movies)) and the $queries variable in: $queries = array(); is never used.
Submit a Comment
Use the following form to submit a comment for this article. You can include any required code snippets, which we will format and highlight accordingly.


Note: Before your comment appears on PhpRiot, it must be manually approved. The email address field is optional. If you choose to include it, it will be displayed obfuscated to protect it from spammers.

In This Article