数据表的class.php并获得如下错误
错误 :
发生SQL错误:SQLSTATE [42000]:语法错误或访问 违规:1064您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以获得正确的语法 在第4行的'ORDER BY request_idASC↵LIMIT0,10'附近使用
我的服务器端代码如下所示,名为 request-list.php
<?php
$inc_files = array("ph_utils");
require_once ('autoload.php');
$db = new db();
$table = 'wallet_load_request';
$primaryKey = 'request_id';
$columns = array(
array('db' => 'request_id', 'dt' => 0),
array('db' => 'request_date', 'dt' => 1),
array('db' => 'trans_mode', 'dt' => 2),
array('db' => 'trans_amt', 'dt' => 3),
array('db' => 'request_status', 'dt' => 4),
array('db' => 'org_id', 'dt' => 5)
);
$sql_details = array(
'user' => PH_DB_USER,
'pass' => PH_DB_PSWD,
'db' => PH_DB,
'host' => PH_DB_HOST
);
require_once('ssp.class.php');
$filterByStaus = isset($_REQUEST['filter_by_status']) ?
$_REQUEST['filter_by_status'] : "PENDING";
switch ($filterByStaus) {
case 'REJECTED':
$fixedFilter .= " AND request_status = 'REJECTED'";
break;
case 'APPROVED':
$fixedFilter .= " AND request_status = 'APPROVED'";
break;
default:
break;
}
$output = SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns,
$fixedFilter);
foreach ($output['data'] as $i => $d) {
$request_id = $output['data'][$i][0];
$trans_amt = $output['data'][$i][3];
$request_status = $output['data'][$i][4];
$org_id = $output['data'][$i][5];
$output['data'][$i][0] = '<div class="text-center"><h4><span class="label label-success"> #'. $request_id .'</span></h4></div>';
if ($request_status == 'APPROVED') {
$output['data'][$i][4] = '<div class="text-center"><span class="label label-success"> APPROVED </span></div>';
$output['data'][$i][5] = '<div class="text-center"><button id="accept" type="button" class="text-center btn btn-success accept disabled" data-request_id=\'' . $request_id . '\' data-org_id=\'' . $org_id . '\' data-trans_amt=\'' . $trans_amt . '\'><i class="fa fa-ban"></i> ACCEPT</button></div>';
$output['data'][$i][6] = '<div class="text-center"><button id="reject" type="button" class="text-center btn btn-danger reject disabled" data-request_id=\'' . $request_id . '\'><i class="fa fa-ban"></i> REJECT</button></div>';
} else if ($request_status == 'REJECTED') {
$output['data'][$i][4] = '<div class="text-center"><span class="label label-danger"> REJECTED </span></div>';
$output['data'][$i][5] = '<div class="text-center"><button type="button" id="accept" class="text-center btn btn-success accept disabled" data-request_id=\'' . $request_id . '\' data-org_id=\'' . $org_id . '\' data-trans_amt=\'' . $trans_amt . '\'><i class="fa fa-ban"></i> ACCEPT</button></div>';
$output['data'][$i][6] = '<div class="text-center"><button type="button" id="reject" class="text-center btn btn-danger reject disabled" data-request_id=\'' . $request_id . '\'><i class="fa fa-ban"></i> REJECT</button></div>';
} else {
$output['data'][$i][4] = '<div class="text-center"><span class="label label-warning"> PENDING </span></div>';
$output['data'][$i][5] = '<div class="text-center"><button type="button" id="accept" class="text-center btn btn-success accept" data-request_id=\'' . $request_id . '\' data-org_id=\'' . $org_id . '\' data-trans_amt=\'' . $trans_amt . '\'><i class="fa fa-ban"></i> ACCEPT</button></div>';
$output['data'][$i][6] = '<div class="text-center"><button type="button" id="reject" class="text-center btn btn-danger reject" data-request_id=\'' . $request_id . '\'><i class="fa fa-ban"></i> REJECT</button></div>';
}
}
SSP::sendJson($output);
我的jquery代码如下 request-list.js
var requestList = {
oTable: {},
init: function () {
requestList.oTable = $('#req_list').dataTable({
"processing": true,
"serverSide": true,
"columnDefs": [{className: "data_middle ", "targets": [0, 1, 2, 3, 4, 5, 6]}],
"columns": [null, null, null, {"orderable": false}, {"orderable": false}, {"orderable": false}, {"orderable": false}],
"ajax": {
"url": "web/request-list",
"data": function (d) {
return $.extend({}, d, {
"filter_by_status": $('#status').val(),
});
}
}
});
}
}
我的前端代码是list.html
<br>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<table class="table table-bordered table-striped table-hover" id="req_list">
<thead>
<tr>
<th>Request ID</th>
<th>DATE</th>
<th>Mode</th>
<th class="text-center">AMOUNT</th>
<th class="text-center">STATUS</th>
<th class="text-center">ACCEPT</th>
<th class="text-center">REJECT</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
运行代码后,页面显示警告为 DataTables警告:table id = req_list - 发生SQL错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法错误;检查与您的MySQL服务器版本对应的手册,以获得正确的语法,用户在第4行的“ORDER BY request_id ASC LIMIT 0,10”附近
并在控制台中我得到错误
jquery.dataTables.min.js:39未捕获的TypeError:无法读取未定义的属性“length”
自定义ssp代码如下面链接
所示https://drive.google.com/open?id=0B-e2dOqifK3QOFFnRjhTYjhPQmM
答案 0 :(得分:0)
如果您想在这种情况下过滤数据,则需要使用complex()
代替simple()
方法。
复杂()方法
SSP::complex($request, $conn, $table, $primaryKey, $columns, $whereResult = null, $whereAll = null)
简单()方法
simple($request, $conn, $table, $primaryKey, $columns)
如果它不适合你,请告诉我们。
答案 1 :(得分:0)
您不需要AND
变量值的前导$fixedFilter
。请参阅下面的更正摘录:
switch ($filterByStaus) {
case 'REJECTED':
$fixedFilter = "request_status = 'REJECTED'";
break;
case 'APPROVED':
$fixedFilter = "request_status = 'APPROVED'";
break;
default:
break;
}
答案 2 :(得分:0)
我只需要更改以下代码
switch ($filterByStaus) {
case 'REJECTED':
$fixedFilter .= " AND request_status = 'REJECTED'";
break;
case 'APPROVED':
$fixedFilter .= " AND request_status = 'APPROVED'";
break;
default:
break;
我正在附加查询,所以我尝试删除。在$ fixedFilter之后
switch ($filterByStaus) {
case 'REJECTED':
$fixedFilter = " AND request_status = 'REJECTED'";
break;
case 'APPROVED':
$fixedFilter = " AND request_status = 'APPROVED'";
break;
default:
break;