Quantcast
Viewing all articles
Browse latest Browse all 82127

search function not working (server side processing)

Hi,

I've implemented a PHP/mysqli server side solution that is working almost perfectly fine. The only thing, for now, that isn't working is the search box.

I've taken the code from there -> http://datatables.net/development/server-side/php_mysqli

I've also searched in the forums here and found some potential solutions/workaround yet none were really what I was looking for.

Here's the 2 JSON response I'm getting

#1 When table is first generated
{
    "sEcho": 2,
    "iTotalRecords": "19",
    "iTotalDisplayRecords": "16",
    "aaData": [
        [
            "2012-12-18 12:18:21",
            "TypeC",
            "123123",
            "321321 ..00",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-18 12:14:04",
            "TypeC",
            "555888",
            "987654321",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-06 13:10:05",
            "TypeA",
            "222222",
            "222222",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-06 13:08:32",
            "TypeA",
            "111111",
            "111111",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-06 13:07:25",
            "TypeA",
            "789789",
            "789789",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-06 13:03:09",
            "TypeA",
            "456456",
            "456456",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-12-06 13:02:09",
            "TypeA",
            "123123",
            "123123",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-30 11:47:25",
            "TypeA",
            "345345345",
            "345345345345",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-29 17:58:12",
            "TypeA",
            "555555",
            "guillaume",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-29 14:24:33",
            "TypeC",
            "654654",
            "jkghlk jhkl",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-29 14:04:55",
            "tres",
            "5555555",
            "hey",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-28 14:34:39",
            "TypeD",
            "9854542",
            "qwerty",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-27 14:55:25",
            "TypeC",
            "456456",
            "I can more than likely write a big comment. I wonder how long can I go.",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-27 14:54:23",
            "TypeD",
            "951753",
            "c'est un autre commentaire",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-12 15:16:27",
            "TypeA",
            "123456",
            "This is a test comment 123123",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ],
        [
            "2012-11-05 15:22:37",
            "TypeC",
            "654321",
            "This is another comment",
            "<button icon=\"ui-icon-pencil2\" onclick=\"resetEditBox()\">Edit</button>"
        ]
    ]
}

and #2, when I get the error (please note that the error appears the minute I type 1 character in the search box):
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`created_date` LIKE '%t%' OR `name` LIKE '%t%' OR `reference` LIKE '%t%' OR `co' at line 2

From my investigation, it appears that the code generating the error is the following:
/**
 * Filtering
 * NOTE this does not match the built-in DataTables filtering which does it
 * word by word on any field. It's possible to do here, but concerned about efficiency
 * on very large tables, and MySQL's regex functionality is very limited
 */
$iColumnCount = count($aColumns);
 
if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
    $aFilteringRules = array();
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
        if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
            $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
        }
    }
    if (!empty($aFilteringRules)) {
        $aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
    }
}

Any hints or help that would help me resolve this will be greatly appreciated. Let me know if there is any more information I can provide to help with this matter.

Cheers

Viewing all articles
Browse latest Browse all 82127

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>