Php 数据表不能与show all一起使用
这是ajax的工作原理:Php 数据表不能与show all一起使用,php,jquery,ajax,datatables,Php,Jquery,Ajax,Datatables,这是ajax的工作原理: $params= $_REQUEST;$columns = array( 0 => 'employee_name', 1 => 'employee_salary', 2 => 'employee_position', 3 => 'employee_city', 4 => 'employee_extension', 5 => 'employee_joining_date', 6 => 'employee_age'); $sq
$params= $_REQUEST;$columns = array(
0 => 'employee_name',
1 => 'employee_salary',
2 => 'employee_position',
3 => 'employee_city',
4 => 'employee_extension',
5 => 'employee_joining_date',
6 => 'employee_age');
$sql = "SELECT employee_id";$sql.=" FROM employee";$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");$totalData = mysqli_num_rows($query);$totalFiltered = $totalData;
$sql = "SELECT employee_name, employee_salary, employee_position, employee_city, employee_extension, DATE_FORMAT(employee_joining_date, '%Y-%m-%d') as employee_joining_date, employee_age ";$sql.=" FROM employee WHERE 1=1";
if( !empty($params['columns'][0]['search']['value']) ){
$sql.=" AND employee_name LIKE '".$params['columns'][0]['search']['value']."%' "; }
if( !empty($params['columns'][1]['search']['value']) ){
$sql.=" AND employee_salary LIKE '".$params['columns'][1]['search']['value']."%' ";}
if( !empty($params['columns'][2]['search']['value']) ){
$sql.=" AND employee_position LIKE '".$params['columns'][2]['search']['value']."%' ";}
if( !empty($params['columns'][3]['search']['value']) ){
$sql.=" AND employee_city LIKE '".$params['columns'][3]['search']['value']."%' ";}
$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");$totalFiltered = mysqli_num_rows($query); $sql.=" ORDER BY ".$columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";$query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees1");
$data = array();while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["employee_name"];
$nestedData[] = $row["employee_salary"];
$nestedData[] = $row["employee_position"];
$nestedData[] = $row["employee_city"];
$nestedData[] = $row["employee_extension"];
$nestedData[] = $row["employee_joining_date"];
$nestedData[] = $row["employee_age"];
$data[] = $nestedData;}
json_data = array(
"draw" => intval( $params['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);echo json_encode($json_data);
我知道有很多代码,但我有这个问题,我单击选项show all in show entries in datatables我得到了这个错误:datatables警告:table id=employee grid-无效的JSON响应。有关此错误的详细信息,请参阅http://datatables.net/tn/1
我不知道为什么索引中有这样的代码:
var dataTable = $('#employee-grid').DataTable({
"bStateSave": false,
"aLengthMenu": [[10, 50, 75, -1], [10, 50, 75, "All"]], //this is your new code
"iDisplayLength": 10, //this is your new code for number of records on page
dom: 'lBfrtip',
buttons: [
{
extend: 'excelHtml5',
title: 'DataTable',
text: '<i class="fa fa-file-excel-o"></i>'
},
{
extend: 'pdfHtml5',
text: '<i class="fa fa-file-pdf-o"></i>',
title: 'DataTable'
},
{
extend: 'csvHtml5',
title: 'Datatable',
text: '<i class="fa fa-file-excel-o"></i>'
}
],
processing: true,
serverSide: true,
ajax: "employee-grid-data.php", // json datasource
})
var-dataTable=$(“#员工网格”).dataTable({
“bStateSave”:false,
“aLengthMenu”:[[10,50,75,-1],[10,50,75,“All”]],//这是您的新代码
“iDisplayLength”:10,//这是页面上记录数的新代码
dom:'lBfrtip',
按钮:[
{
扩展:“excelHtml5”,
标题:“数据表”,
文本:“”
},
{
扩展:“pdfHtml5”,
文本:“”,
标题:“数据表”
},
{
扩展:“csvHtml5”,
标题:“数据表”,
文本:“”
}
],
处理:对,
服务器端:是的,
ajax:“employee grid data.php”,//json数据源
})
这是我在单击all时从ajax中得到的:employee-grid-data.php:get employees1
我不知道为什么当我选择all nothing works时,我知道它来自ajax调用,但我不知道它是什么,请帮助提前感谢你,并为大量代码感到抱歉你能发布ajax请求返回的原始数据吗?done it@freytagReplace
json\u data=array(
with$json\u data=array(