【发布时间】:2018-04-06 07:37:16
【问题描述】:
简介 我在做一个服务器端datatables.net json插件。
错误
一旦我尝试添加我的最后一列和第六列<th>Action,,我就会收到以下错误消息:
"DataTables 警告:表 id=example - 请求的未知参数 '6' 表示第 0 行第 6 列。有关此错误的更多信息,请 见http://datatables.net/tn/4"
我以前收到过此错误消息,并且知道它的一般含义。但是为什么它试图从数据库中提取数据呢?我从来没有用过$subdata[]=$row[6]; 我什至在这里看了一个视频:https://www.youtube.com/watch?v=tCB2BHCVSjs。此外,当您在错误消息上单击“确定”时,表格会完全正常加载(没有按钮除外)。
Index.php:
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Date</th>
<th>Updated</th>
<th>Action</th>
</tr>
</thead>
</table>
<?php
$records = mysqli_query($con, "SELECT * FROM employees");
$totalData= $records->num_rows;
$totalFiltered=$totalData;
$data=array();
while ($row = mysqli_fetch_array($records)) {
$subdata=array();
$subdata[]=$row[0]; //id
$subdata[]=$row[1];
$subdata[]=$row[2];
$subdata[]=$row[3];
$subdata[]=$row[4];
$subdata[]=$row[5];
$subdata[]='<button></button>';
$data[]=$subdata;
}
$requestData= $_REQUEST;
Server.php
$json_data = array(
"draw" => intval(isset($_GET['draw'])),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data //How To Retrieve This Data
);
echo json_encode($json_data);
?>
$table = 'employees';
// Table's primary key
$primaryKey = 'id';
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'first_name', 'dt' => 1 ),
array( 'db' => 'last_name', 'dt' => 2 ),
array( 'db' => 'position', 'dt' => 3 ),
array( 'db' => 'date', 'dt' => 4 ),
array( 'db' => 'updated', 'dt' => 5 ),
);
// SQL server connection information
$sql_details = array(
'user' => 'id3741634_username',
'pass' => 'password',
'db' => 'id3741634_database',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
【问题讨论】:
标签: php json datatables