phpjquerymysqldatatablesssp

php-mysql datatables with Datatable Server processing ssp.class.php Script


I am trying to create a data grid using [Datatables][1] Jquery plugin and process it on the server using provided ssp.class.php. It did work but i ran into problem when i want to fetch data from multiple tables. I used The modified form created by emram. I have followed the steps and am still getting error like (invalid string offset 0) and the same class seemed to be working people. Here is my code.

<?php

$table ="property";
        $primaryKey = 'property.propertyID';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
       /* $columns = array(
            array( 'db' => 'propertyNAme', 'dt' => 0 ),
            array( 'db' => 'propertyAddress',  'dt' => 1 ),
            array( 'db' => 'propertyCode',   'dt' => 2 ),
            array( 'db' => 'propertyRegistrationNumber',     'dt' => 3 ),
            array( 'db'   => 'createdAt','dt' => 4,'formatter' => function( $d, $row ) {return date( 'jS M y', strtotime($d)); }),
            array('db'  => 'propertyPrice', 'dt'=> 5,'formatter' => function( $d, $row ) { return '$'.number_format($d); } )
        );*/
        $sql_details = array(
            'user' =>APP_SYSTEM_DB_USER_NAME,
            'pass' => APP_SYSTEM_DB_USER_PASSWORD,
            'db'   => APP_SYSTEM_DB_NAME,
            'host' => APP_SYSTEM_DB_HOST
        );
        $columns = array(
            array( 'db' => 'p.propertyName',    'dt' => 0, 'field' => 'Property Name' ),
            array( 'db' => 'p.propertyAddress',  'dt' => 1, 'field' => 'Address' ),
            array( 'db' => 'p.propertyCode',        'dt' => 2, 'field' => 'Property Code' ),
            array( 'db' => 'p.propertyRegistrationNumber',  'dt' => 3, 'field' => 'Reg No'),
            array( 'db' => 'p.propertyPrice',           'dt' => 4, 'field' => 'email' ),
            array( 'db' => 'p.createdAt', 'dt' =>5,'field' => 'date','formatter' => function( $d, $row ) {return date( 'jS M y', strtotime($d)); }),
            array( 'db' => 'c.countryName',             'dt' => 6, 'field' => 'Country'));
        $joinQuery = " FROM `{$table}` AS p LEFT JOIN country AS c ON (c.countryID = p.propertyCountryID)";
        $extraWhere="";
           $data= \app\models\datatable\helper\SSP::simple($_GET, $sql_details,$table, $primaryKey, $columns,$joinQuery, $extraWhere);
echo json_encode($data)


Solution

  • Thanks!. I have figured it out my self. I was sanitizing my $_GET variables before calling

    $_GET =$validator->sanitize($_GET)->xss_clean($_GET); 
    SSP::simple($_GET...)
    I just commented this code out and it worked . It works now –