MORE THAN 10 RECORDS DISPLAYED DURING SERVER SIDE PROCESSING

MORE THAN 10 RECORDS DISPLAYED DURING SERVER SIDE PROCESSING

martin muriithimartin muriithi Posts: 1Questions: 1Answers: 0
edited December 2019 in Free community support

why does datatables display more than 10 records when loading data from server side.
it displays showing " 1 to 10 of 50 entries" though it displays all the 50 records.

//script being used:
  var datatable=$("#ExampleTable").DataTable({
      "processing" : true,
    "serverSide" : true,
    "ajax" : {
     url:"fetch.php",
     type:"POST"
    },
  })

```
//server side:

<?php

//user_fetch.php

$connect=new PDO("mysql:host=localhost;dbname=airline2","root","");

$query = '';

$output = array();

$query .= "
SELECT * FROM user_details
";

if(isset($_POST["search"]["value"]))
{
$query .= ' where user_id LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR username LIKE "%'.$_POST["search"]["value"].'%" ';

}

$statement = $connect->prepare($query);

$statement->execute();

$result = $statement->fetchAll();

$data = array();

$filtered_rows = $statement->rowCount();

foreach($result as $row)
{
$status = '';

$sub_array = array();
$sub_array[] = $row['user_id'];
$sub_array[] = $row['username'];

$data[] = $sub_array;
}

$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $filtered_rows,
"recordsFiltered" => get_total_all_records($connect),
"data" => $data
);
echo json_encode($output);

function get_total_all_records($connect)
{
$statement = $connect->prepare("SELECT * FROM user_details");
$statement->execute();
return $statement->rowCount();
}

<?php > ``` ?>

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It doesn't, see here, so it'll be something to do with your script. Check the Ajax tab on that example, and you'll see what the server should be sending back. The protocol is discussed here.

    Cheers,

    Colin

This discussion has been closed.