server side pagination don't work

server side pagination don't work

quattrocordequattrocorde Posts: 2Questions: 0Answers: 0

Hello to everyone
I want to use server side script to "print" data from my database to a dataTable

I can read all data from my database, correctly sort, and correctly search, but the pagination don't work !

mySql table contains 15 record;

when I load the dataTable, I see all 15 record (but I see "show 10 entry" ) and the pagination, show "previus 1, 2, next" but without any link

How can I resolve this problem ?!

Thank You for everything !!

this is my javascript

<script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable( {
    /*dom: '1Bfrtip', //or Bfrtip ?!?
        buttons: [
            'csv','pdf','excel'
        ],*/
    "processing": true,
        "serverSide": true,
        "ajax": {
        url:"dataTableQuery.php",
        type:"post"
    }
    } );
} );
</script>

and this is my dataTableQuery.php

```
<?php

require_once(DIR ."/_config/config.php");
$config = new config();

require_once(DIR ."/$config->directoryConfig/database_class.php");
require_once(DIR ."/$config->directoryClass/classAdmin.php");

$lettera = $_GET['lettera'];
if ( isset($lettera) ) {

$filtro_GET = "AND engine LIKE '%$lettera' ";

}

$request = $_REQUEST;

$col = array(

0 => 'id',
1 => 'engine',
2 => 'browser',
3 => 'platform',
4 => 'version',
5 => 'grade'

);

$db = new database();
$sql = "SELECT * FROM ajax WHERE 1=1 $filtro_GET";

if ( !empty($request['search']['value']) ) {

$sql.=" AND (engine LIKE'%".$request['search']['value']."%' ";
$sql.=" OR browser LIKE'%".$request['search']['value']."%' ";
$sql.=" OR platform LIKE'%".$request['search']['value']."%' ";
$sql.=" OR version LIKE'%".$request['search']['value']."%' ";
$sql.=" OR grade LIKE'%".$request['search']['value']."%' ) ";

}

//$sql.= " ORDER BY ".$col[$request['order'][0]['column']]." ".$request['order'][0]['dir']." LIMIT ".$request['start']." ,".$request['length']." ";
$sql.= " ORDER BY ".$col[$request['order'][0]['column']]." ".$request['order'][0]['dir']." ";
//$sql.= " LIMIT ".$request['start']." ,".$request['length']." ";

$db->query($sql);
$db->execute();

$totalData = $db->rowCount();
$totaleFilter = $totalData;

$data = array();

while ( $row = $db->single() ) {

$subdata = array();

$link = "<a href=\"#\">$row[engine]</a>";

$subdata [] = $row[id];
$subdata [] = $link;
$subdata [] = $row[browser];
$subdata [] = $row[platform];
$subdata [] = $row[version];
$subdata [] = $row[grade];
$data[] = $subdata;

}

$json_data = array(
"draw" => intval($request['draw']),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totaleFilter),
"data" => $data
);

echo json_encode($json_data);

<?php > ``` ?>

Replies

  • quattrocordequattrocorde Posts: 2Questions: 0Answers: 0

    Ok I resolve with this code: (error in php query...)

    ```
    <?php

    require_once(DIR ."/_config/config.php");
    $config = new config();

    require_once(DIR ."/$config->directoryConfig/database_class.php");
    require_once(DIR ."/$config->directoryClass/classAdmin.php");

    $lettera = $_GET['lettera'];
    if ( isset($lettera) ) {

    $filtro_GET = "AND engine LIKE '%$lettera' ";
    

    }

    $request = $_REQUEST;

    $col = array(

    0 => 'id',
    1 => 'engine',
    2 => 'browser',
    3 => 'platform',
    4 => 'version',
    5 => 'grade'
    

    );

    $db = new database();
    $sql = "SELECT * FROM ajax WHERE 1=1 $filtro_GET";

    if ( !empty($request['search']['value']) ) {

    $sql.=" AND (engine LIKE'%".$request['search']['value']."%' ";
    $sql.=" OR browser LIKE'%".$request['search']['value']."%' ";
    $sql.=" OR platform LIKE'%".$request['search']['value']."%' ";
    $sql.=" OR version LIKE'%".$request['search']['value']."%' ";
    $sql.=" OR grade LIKE'%".$request['search']['value']."%' ) ";
    

    }

    $db->query($sql);
    $db->execute();

    $totalData = $db->rowCount();
    $totaleFilter = $totalData;

    $sql.= " ORDER BY ".$col[$request['order'][0]['column']]." ".$request['order'][0]['dir']." LIMIT ".$request['start']." ,".$request['length']." ";
    //$sql.= " ORDER BY ".$col[$request['order'][0]['column']]." ".$request['order'][0]['dir']." ";
    //$sql.= " LIMIT ".$request['start']." ,".$request['length']." ";

    $db->query($sql);
    $db->execute();

    $data = array();

    while ( $row = $db->single() ) {

    $subdata = array();
    
    $link = "<a href=\"#\">$row[engine] - LIMIT $request[start],$request[length]</a>";
    
    $subdata [] = $row[id];
    $subdata [] = $link;
    $subdata [] = $row[browser];
    $subdata [] = $row[platform];
    $subdata [] = $row[version];
    $subdata [] = $row[grade];
    $data[] = $subdata;
    

    }

    $json_data = array(
    "draw" => intval($request['draw']),
    "recordsTotal" => intval($totalData),
    "recordsFiltered" => intval($totaleFilter),
    "data" => $data
    );

    echo json_encode($json_data);

    <?php > ``` ?>
This discussion has been closed.