Sort Columns

Add a sort option to the top of a table column.

To allow a column to be sortable, we need to add " :sort  " after the title of the header of the column in the $td_titles array. Then we specify the column name of the databse that will be used to sort the table in the new query.
 

array_push($td_titles,"140-CLIENT:sort:NAME");

 

Advanced Options
We can add more properties like Title, Sort and Width by passing an array on each $td_titles value

 

$th = array(
'name'=> 'Client',
'title'=> 'Client Name', //hover title attribute (optional)
'width'=> 140, //(optional)
'sort'=>'NAME' //(optional)
);

array_push($td_titles,$th);


or short version:

 

array_push($td_titles,array('name'=> 'CLIENT','title'=> 'CLIENT NAME','width'=> 140,'sort'=>'NAME'));

 

In this example 140 is the width of the column, CLIENT is the title to show and sort:NAME indicates that it will sort the table by the databse column name NAME.

Then we need to add the conditional before our query that will modify the order of the results,  $orderby and $asde are predefined variables, in the first part we define our defaults, in this case order by REG_DATE DESC:

 

if(!isset($ob)){
    $orderby = 'REG_DATE';
    $asde = 'DESC';
}else{
    $orderby = $ob;
}
 
 
And finally incorporate these variables to our query:
 
 
$query = "SELECT CID, NAME, EMAIL, TEL, REG_DATE FROM $dbtable %%WHERE%% order by $orderby $asde";
 
Get a Quote

Get a Quote