Sortable Elements PHP Class
Back to home page | View demo
This PHP class, Sortable Elements is designed to make use of various frameworks in order to make it extremely easy to sort
and edit database elements. Namely, it ultilizes the scriptaculous framework in order to allow DRAGGING of
the elements up and down to sort them (a very elequent solution to this once tricky problem).
This class also ultilizes AJAX to allow you to edit the names of the element within the draggable tab.
Combined into a easy-to-use class (so you don't need to toy around with function calls, javascript references, etc), you can now implement in seconds what once would take a skilled programmer hours.
This demo assumes you all ready have a table created with sortable elements in it. If this was not the case you probably would not be interested in this class.
However, for the purposes of demostration, I will include the below steps for creating a mySQL table with sample sortable data:
CREATE TABLE tblFriends(
pkFriendID INT PRIMARY KEY AUTO_INCREMENT,
fldName VARCHAR(100),
fldSort INT
);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Sean Dempsey', 1);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Meg Ryan', 2);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Justin Rigby', 3);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Chuck Mangione', 4);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Kurt Duprey', 5);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Chuck Mangione', 6);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Mason Williams', 7);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Edward William Blake', 8);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Saddam Hussain', 9);
INSERT INTO tblFriends (fldName, fldSort) VALUES ('Melissa Abrami', 10);
The above SQL creates a table of friends and then populates the table with 10 values. The sort order can be thought of as an integer repesentation of how well you like each friend. 1=Very good friend. 10=Thoughts of deep-seeded masocism.
Ok. Anyway though ... so onto the fun part. Let's sort them and edit their values via the class: