The general approach often used is to have the sortable column headings be clickable links. The links would include a URL query string name=value pair that the target script would use via the $_GET array to determine how to sort the data when it queries it from the DB. The simplest thing then is to have clicking it reload the page using the new sorting criteria. Additionally, you could take an AJAX approach and add an onclick event to the link that would instead call a JavaScript AJAX function to send the URL/query string to a PHP script which would do the query, then return sorted data which the page's JavaScript would use to just redisplay the HTML table with the new sorting, rather than reloading the entire page.
Another alternative is to just initially include all the data in JavaScript array, and then once the page is loaded the column sorting links' onclick events would do the sorting via JavaScript only based on that array, with no further communication with the host.
Each technique has its pros and cons, and ideally if you use either the AJAX or the pure JavaScript method, you code it such that it will "degrade" to the first method (just reloading the page) for the very small percentage of users who browse without JavaScript available/enabled.