Of course, no data table is complete without filtering. There's no point having a few million results if you can't narrow it down to a manageable level.
The URL string we're working with includes a number of sSearch
parameters: the sSearch
parameter itself and an sSearch_0/1/2/3
parameter for each of the table columns. We will only use the main sSearch
in this chapter's example.
In our example, we will take the string we're given, and match it against the beginning of the city name field, and if there are exactly two letters, will also match it against the country.
First, we need to set up MySQL's where
clause. Add this to the "initialize variables" section of get_data.php
:
// { search $search_sql=''; if(isset($_REQUEST['sSearch']) && ''!=$_REQUEST['sSearch']){ $stext=addslashes($_REQUEST['sSearch']); $search_sql='where '; if(strlen($stext)==2) $search_sql.="ccode='$stext' or "; $search_sql.="city like '$stext%'"; } // ...