In the URL string shown in the last section, there are a few parameters to do with sorting:
iSortingCols
: This defines the number of columns that we are sorting. (We'll stick with just one for this chapter.)iSortCol_0
: This defines the first column to sort. The value is numerical, starting with 0, and corresponds to what columns are displayed in the table, not the fields in the database.iSortDir_0
: This defines the direction the column should be sorted in. Handily, this value is eitherasc
ordesc
, which we can plug directly into the query.
To make use of the numerical nature of iSortCol_0
, we will add an array of column names to get_data.php
. Add it to the "initialize variables" block:
$cols=array('ccode','city','longitude','latitude');
And then, we will generate MySQL's order
by
clause's information by adding the following just below this line:
// { sort by $scol=0; if(isset($_REQUEST['iSortCol_0'])){ $scol=(int)$_REQUEST['iSortCol_0']; if($scol>3 || $scol...