Sorting records data by column header in paging scriptPaging script can be customized further to add more features. One of the feature is to manage the display the records in order of the data. This way data can be sorted based on the columns names. Please read the basic php paging script to understand how the paging works. Now to this script we will add column header sorting feature. Here users can click the column names as hyperlinks and manage the display order by sorting the data. Here we will use all column headers ad hyperlink and take the column name to the address bar. Then collect the column name from address bar and add the order by query using the column name. Note the hyper link for a column header here. <a href='$page_name?column_name=name'>Name</a>Now the page will reload with the column name at the address bar. Then we will collect this column name by this line.@$column_name=$_GET['column_name'];Since the data for the variable $column_name we are getting from the query string and we are going to use in our sql , we must check and sanitize the data before using. The data should be alpha numeric only, so let us use the function ctype_alnum and check.if(strlen($column_name) > 0 and !ctype_alnum($column_name)){
After this we will use one if condition to add order by clause to query. Like this .
| ||
| ||