Friday, February 24th, 2006
> phpRiot has posted a tutorial that pairs PHP and Ajax together (the perfect combination?) to create sortable lists.
ou might have been in a situation before where you had a list of items in your database that needed to be output in a specific order. These items could be anything: perhaps a listing of your favourite movies or your favourite books. For whatever reason, you want them ordered in a custom way that canâ€™t be determined automatically (such as alphabetical).
This article covers the implementation of a system that lets you easily define the order of such a list.
The lists they feature are the drag-and-drop types, created with the help of the Prototype and Scriptaculous libraries. A fully-interactive example of the lists is shown on the first page of the tutorial.
They walk through the creation of the entire setup, both client-side and server-side, deatiling each of these steps along the way:
- the database creation, showing how the table is defined – shown for both MySQL and PostgreSQL
- the PHP code used to generate the list output to the browser via a database layer and two logic/output files
- adding the drag-and-drop capability to the script, via Scriptaculous and some CSS
- writing the PHP script to handle the sorting changes (the script Ajax calls)
- and, finally, working up the Ajax code to be fired off when the user changes the order of the list
Posted by Chris Cornutt at 11:16 am