php - 数据表服务器端错误
问题描述
由于未来数据的聚集,我正在使用服务器端数据表开发新闻列表,但我遇到了一个小问题。
问题是当我将数据附加到 $nestedData 中的列时,它将打印所有数据,仅适用于第二列。发生错误:DataTables 警告:table id = server-side - Requested unknown parameter '2' for row 0, column 2。有关此错误的更多信息,请参阅http://datatables.net/tn/4
如果我添加以打印第三列,则会出现错误!无数据表。根据照片。
代码JS
<script>
$(document).ready(function(e){
$('#server-side').dataTable({
"bProcessing": true,
"serverSide": true,
language: {
processing: "Processando...",
},
"ajax":{
url :"server-side/nov.php",
type: "POST",
},
"order": [ 0, "desc"],
});
table.destroy();
table = $('#server-side').DataTable( {
searching: false
} );
});
代码服务器端
<?php
require_once '../database/mysql.php'; $db = new Mysql;
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
$columns = array(
0 => 'noticia_id',
1 => 'noticia_foto',
2 => 'noticia_title',
3 => 'noticia_category',
4 => 'noticia_data',
5 => 'noticia_autor'
);
$where_condition = $sqlTot = $sqlRec = "";
if( !empty($params['search']['value']) ) {
$where_condition .= " WHERE ";
$where_condition .= " ( noticia_title LIKE '%".$params['search']['value']."%' ";
$where_condition .= " OR noticia_content LIKE '%".$params['search']['value']."%' )";
}
$sql_query = "SELECT noticia_id, noticia_foto, noticia_title, noticia_category, noticia_data, noticia_autor FROM noticia ";
$sqlTot .= $sql_query;
$sqlRec .= $sql_query;
if(isset($where_condition) && $where_condition != '') {
$sqlTot .= $where_condition;
$sqlRec .= $where_condition;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$db->query( $sqlTot )->fetchAll();
$totalRecords = $db->rows;
$db->query( $sqlRec )->fetchAll();
if ($db->rows >= 1):
$querys = $db->data;
foreach ($querys as $query):
$q = (object) $query;
if ( $q->noticia_foto == "" || strlen( $q->noticia_foto ) <= 1 )
{
$foto = "../images/sem-foto.jpg";
}
else
{
$foto = "../thumb.php?img=uploads/noticias/$q->noticia_foto";
}
$queryRecords = $db->rows;
$nestedData = array();
$nestedData[] = $q->noticia_id;
$nestedData[] = "<img src=\"$foto\" style=\"width:40px; height:30px;\" />";
// Just print so far
//$nestedData[] = $q->noticia_title;
//$nestedData[] = $q->noticia_category;
//$nestedData[] = $q->noticia_data;
//$nestedData[] = $q->noticia_autor;
//$nestedData[] = "Ações";
$data[] = $nestedData;
endforeach;
endif;
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval( $totalRecords ),
"data" => $data
);
echo json_encode($json_data);
?>
解决方案
推荐阅读
- angular8 - 有什么用?。在角度
- laravel - 当我使用 session->all 时,为什么我的数据库中的会话数据与会话数据不同?
- javascript - 如何在 ajax 调用期间从 Rails 控制器方法返回值?
- python - 如何提取非结构化的excel文件数据(仪表板数据)并将其导出为结构化的干净数据
- typescript - 如何键入函数表达式及其内部对象 - TypeScript 3
- reporting-services - 如何检查架构更改对 SSRS 服务器上所有报告的影响?
- git - 无法在 Azure DevOps 上完成拉取请求
- python - 在 python 中验证 Github 私有仓库
- python - 硒中的 NoSuchFrameException(frame_reference)
- java - JsonDeserialize 可选字段设置为 Optinal.empty 的 Java 构建器类。JsonDeserialize 时设置默认值