Data Tables Search Not Working (PHP | Mysqli)
Data Tables Search Not Working (PHP | Mysqli)
Hello All,
I have a Table, and i'm getting data from database using datatable. everything working fine but when i use search its not working. my code post search value on my serverside page and i Don't know what is mean in "bSearchable_" and "sSearch_". I'm stuck here from last 2 Days. Please Help me to out.
$sWhere = "";
$iColumnCount = count($aColumns);
if ( isset($input['search']) && $input['search'] != "" ) {
$aFilteringRules = array();
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'false' ) {
$aFilteringRules[] = "".$aColumns[$i]."
LIKE '%".$db->real_escape_string( $input['search'] )."%'";
}
}
if (!empty($aFilteringRules)) {
$aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
}
}
// Individual column filtering
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
$aFilteringRules[] = "".$aColumns[$i]."
LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
}
}
if (!empty($aFilteringRules)) {
$sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
} else {
$sWhere = "";
}
/**
* SQL queries
* Get data to display
*/
$aQueryColumns = array();
foreach ($aColumns as $col) {
if ($col != ' ') {
$aQueryColumns[] = $col;
}
}
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".implode("
, ", $aQueryColumns)."
FROM ".$sTable."
".$sWhere.$sOrder.$sLimit;
$rResult = $db->query( $sQuery ) or die($db->error);
// Data set length after filtering
$sQuery = "SELECT FOUND_ROWS()";
$rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
list($iFilteredTotal) = $rResultFilterTotal->fetch_row();
// Total data set length
$sQuery = "SELECT COUNT(".$sIndexColumn."
) FROM ".$sTable."
";
$rResultTotal = $db->query( $sQuery ) or die($db->error);
list($iTotal) = $rResultTotal->fetch_row();
Answers
bSearchable_
andsSearch_
are legacy parameters. They are described in the legacy documentation.The documentation for the current parameters is available here.
Allan