I've seen loads of tables where I can click on the heading title and it will sort the table in order - does anyone know how this is done or any good tutorials on it? :thumb:
Printable View
I've seen loads of tables where I can click on the heading title and it will sort the table in order - does anyone know how this is done or any good tutorials on it? :thumb:
Usually the data displayed is from a database which is where the sorting takes place.
eg.
PHP Code://When page loads for first time show in ASC order
$sSQL = "SELECT * FROM YourTable ORDER BY YourField ASC"
//Then when column heading is clicked do the opposite sorting.
$sSQL = "SELECT * FROM YourTable ORDER BY YourField DESC"
Thanks for that - I was wondering when the user clicks on the column does it call a function on another php page or a function within the same page??? How does it work - do you have any examples?
This link should help you out :thumb:
Hmmm, nope there's an error - I get: 'Error: A problem was encountered while executing this query.'
Strange.... anyway I'll search on this topic for more info...
Use the query string to specify the field to sort by and the direction.
Ensure that these values are properly sanitized in your code to ensure no other data except the column name appears in the query.
Have you got any examples pleasE?????
Write it yourself and stop being lazy.Quote:
Originally Posted by wwwfilmfilercom
http://google.com/search?q=query+string+phpQuote:
Originally Posted by wwwfilmfilercom
The link that lintz provided gives enough information and example of the very thing you want, except you probably want to include the ability to either sort by ascending or descending, which is just another quick step. in the link he posted, you use $_GET['order'] for the column name you're sorting by and you could just add $_GET['sort'] or something that would contain either "ascending" or "descending" (or any shortened abbreviations, like asc/desc, a/d, etc), then you just tack the command (either ASC or DESC) onto the end of your query and you're ready to go.
it's quite simple, really.
Cheers