undefined index: columns, one silly and irritating error while using Datatables library

This Error occurred suddenly in one of my project listing page and it takes my lots of hour to find out the solution. That’s why think to share the experience.

What I found after searching is its happened may be for two reason

  • The encoded array from ssp.class.php was not in UTF-8 what is needed for json_encode.
  • And another one reason if the column array is big then the big URL size makes it problem if you are using GET method while server side processing.

So What’s the solution 🙂

First reason’s solution is at SSP Class you have to add following line after PDO connect after line no #272 to define character set.

$db->query("SET NAMES 'utf8'");

Or you can see my cutomised SSP class .

And second reason’s solution is you have to do use POST instead of GET while server side AJAX call.

While assign the URL you have to use HTTP type POST.

"ajax": {
"url": "scripts/post.php",
"type": "POST"
},

And little reminder is at server side script use POST instead of GET variable while calling SSP simple function. Like

$Ssp::simple( $_POST, $sql_details, $table, $primaryKey, $columns)

You can see the POST examples here. 

Hope it may help. 🙂

Thanks

Advertisements

5 thoughts on “undefined index: columns, one silly and irritating error while using Datatables library

    • Emran Ul hadi says:

      Thanks Oluwaniran,

      It’s really feel good to hear that it helps.
      And Thanks for the suggestion about donation link. 🙂
      Your comments encouraging me, really appreciate it.

  1. Hope someone can help me

    1. at ssp.customized.class.php line 223 the UTF8 is set, may be Emran has update his code

    */
    static function simple ( $request, $sql_details, $table, $primaryKey, $columns, $joinQuery = NULL, $extraWhere = ”, $groupBy = ”)
    {
    $bindings = array();
    $db = SSP::sql_connect( $sql_details );
    $db->query(“SET NAMES ‘utf8′”);

    2. even I use POST method, I still got same error as below which cannot find columns, draw,

    Notice: Undefined index: columns in /home/xxx/public_html/modules/mod_aa_prog_xxx/php/ssp.customized.class.php on line 166 Call Stack: 0.0003 237208 1. {main}() /home/xxx/public_html/modules/mod_aa_prog_xxx/php/class.php:0 0.0016 250816 2. SSP::simple() /home/xxx/public_html/modules/mod_aa_prog_xxx/php/class.php:90 0.0021 259360 3. SSP::filter() /home/xxx/public_html/modules/mod_aa_prog_xxx/php/ssp.customized.class.php:228 Notice: Undefined index: draw in /home/xxx/public_html/modules/mod_aa_prog_xxx/php/ssp.customized.class.php on line 276 Call Stack: 0.0003 237208 1. {main}() /home/xxx/public_html/modules/mod_aa_prog_xxx/php/class.php:0 0.0016 250816 2. SSP::simple() /home/xxx/public_html/modules/mod_aa_prog_xxx/php/class.php:90

    {“draw”:0,”recordsTotal”:360,”recordsFiltered”:30,”data”:[[“3749″,”SFF-0516″,”Sports Science & Fitness Foundation Course”,”H150675″,”PASS”],[“3749″,”SFF-0516″,”Sports Science & Fitness Foundation Course”,”H160145″,”PASS”],

    Anyone who still have the same problem on line 166, line 276 please share your solved method,

    If possible, Emran, please do help

    Thanks
    Fion

Leave a Reply to Sheryar Shirazi Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s