Sortable Elements PHP Class - Page 2Back to page 1 | Back home page
To implement the PHP class in your code simply use the following ONE LINE:
$sorting = new Sortable_Elements("Friend", "tblFriends", "pkFriendID", "fldName", "fldSort");
The class takes 5 (five) parameters:
- The first is what each element in the table IS (for example, in this case, it's a table of friends). Make sure the parameter is the singular noun.
- The second parameter is the name of the table you are querying from.
- The third parameter is the primary key for each element in the table. (If this is in any way confusing, please reference database design elements for more information on the purposes of primary keys.)
- The forth parameter is the name of database field that you will be displaying/sorting/editing/adding/etc
- The final and fifth parameter is the name of the database field which is used for sorting.
Voila. You now have a functioning "sorting" application. Pretty nifty.
Click on the text/label for an element to turn it into a editable textbox. This allows you to actually edit the name of that item. For example, click the first name in the demo, Sean Dempsey. Change the name to whatever you want. Press enter. Instantly (and without page refresh) the database entry is changed.
Drag the order of the names up and down (grab the handle bar on the right). Click the "Save Sorting Order" button at the bottom. Your sorting preferences will be saved.