【发布时间】:2018-06-29 16:01:21
【问题描述】:
我使用库在表中呈现我的数据库: https://datatables.net/
我的问题是它只能很好地排序我的第一个列。
在代码方面是[0],我的第一列是"id"。
每次我尝试设置它时,我都会从 Chrome 的网络检查中收到此消息错误
<br />
<b>Notice</b>: Undefined offset: 2 in <b>/.../xxx/.../appel.php</b> on line <b>22</b><br />
<br />
<b>Fatal error</b>: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'asc LIMIT 0, 10' at line 1 in .../xxx/.../appel.php:37
Stack trace:
#0 .../xxx/.../appel.php(37): PDOStatement->execute()
#1 {main}
thrown in <b>.../xxx/.../appel.php</b> on line <b>37</b><br />
我的头发正在脱落,我完全不知道会发生什么...... 在documentation 我看到了
order[i][column] integer Column to which ordering should be applied. This is an index reference to the columns array of information that is also submitted to the server.
order[i][dir] string Ordering direction for this column. It will be asc or desc to indicate ascending ordering or descending ordering, respectively.
所以这应该可行........
这是我的 AJAX 调用
var dataTable = $('#tableau').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"actions/appel.php", // adresse du script AJAX
type:"POST"
},
"columnDefs":[
{
"targets":[3, 4, 5], // exeptions des ordres de triage
"orderable":false,
},
],
});
和我的 PHP 代码 (appel.php)
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$_POST['order'][2]['column'].' '.$_POST['order'][0]['dir'].' ';
}
else
{
$query .= 'ORDER BY id DESC ';
}
有人知道会出什么问题吗?!?
【问题讨论】:
标签: php jquery ajax sorting datatables