I have a table in database that has 2 columns Name | Age, I display it in a HTML page.
I want to sort the table in HTML page based on a field when the user clicks on it.
I have a PHP function to do the sorting based on a field.
But after obtaining the rows in sorted order in PHP, I’m looking for ways by which I can update the HTML table without navigating away from the page.
You can do sorting in javascript, without having to communicate with the server. For example, this code will sort a table based on the content of the Nth column:
For example, to sort the first table in the document, on the first column, and skip the header row:
Obviously you’ll want to modify this to suit your own tastes, especially the sorting, but it’s a lot simpler than having to post the data back to the server, which I think is what you’re proposing.