I am using the jquery plugin Datables and I am using the php processing file to do filtering. I have already modified the code to allow for multiple keywords.but if I input a space as a starting char I get a JSON error is it possible to ignore this error without having to click ok? or is there a way to modify the php to allow spaces to start.
thanks
heres some code:
$sWhere = "";
if ( $_GET['sSearch'] != "")
{
$aWords = preg_split('/\s+/', $_GET['sSearch']);
$sWhere = "WHERE (";
for ( $j=0 ; $j<count($aWords) ; $j++ )
{
if ( $aWords[$j] != "" )
{
if(substr($aWords[$j], 0, 1) == "!"){
$notString = substr($aWords[$j], 1);
$sWhere .= "(";
for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
$sWhere .= $aColumns[$i]." NOT LIKE '%".mysql_real_escape_string( $notString )."%' AND ";
}
$sWhere = substr_replace( $sWhere, "", -4 );
}
else{
$sWhere .= "(";
for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $aWords[$j] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
}
$sWhere .= ") AND ";
}
}
Your problem is with
preg_split()operating on a single-space string:Splitting a single space will return an array of two blank strings. Change the first lines to this:
This way, you don’t try and run the code with a basically blank string.