I have a jQuery/PHP tutorial i followed in a book that created pagination that uses Ajax to retrieve the records from a MySQL table each time the page is changed using the limit clause in the SQL statement. I'd like to add the ability to have the user click the column headings to sort them but i tried tablesorter but that just sorts the visible records. Is there a way to sort in the SQL statement and have it remember the sorting if the user clicks the next or previous buttons?
I would suggest having a URL parameter for the page which holds the current column you would like to order by. You can then append something similar to
"ORDER BY ".$_GET["order"] to the end of your SQL query. Then simply make each column heading a link to the page with
?order=column added to the end, replacing "column" with whatever column in the table you want it to be ordered by.
Of course, you should use something like mysql_real_escape_string to make sure that the URL parameter is safe to use in the query.