我正在尝试在我的项目中实现JQuery Bootgrid来显示MySQL数据库中的数据。我正在查询的数据显示在分页表中,但是当我尝试搜索某些数据时,它向我显示"未找到结果"。我已在命令行和我的查询中测试了我的查询没关系,它正在返回我想要的结果。
SELECT * FROM radcheck rc LEFT JOIN radusergroup ON rc.username=radusergroup.username LEFT JOIN userinfo ON rc.username=userinfo.username LEFT JOIN radusergroup disabled ON disabled.username=userinfo.username AND disabled.groupname = 'daloRADIUS-Disabled-Users' WHERE username LIKE 'admin';
我认为' WHERE'条款好像我尝试在上面的查询中使用admin而没有引号它向我显示错误 未知列' admin'在' WHERE'条款 即可。同样的问题也可能出现在我的PHP代码中。请帮助..
fetch.php
<?php
//fetch.php
include("connection.php");
$query = '';
$data = array();
$records_per_page = 10;
$start_from = 0;
$current_page_number = 0;
if(isset($_POST["rowCount"]))
{
$records_per_page = $_POST["rowCount"];
}
else
{
$records_per_page = 10;
}
if(isset($_POST["current"]))
{
$current_page_number = $_POST["current"];
}
else
{
$current_page_number = 1;
}
$start_from = ($current_page_number - 1) * $records_per_page;
$query .= "SELECT * FROM radcheck rc LEFT JOIN radusergroup ON rc.username=radusergroup.username LEFT JOIN userinfo ON rc.username=userinfo.username LEFT JOIN radusergroup disabled ON disabled.username=userinfo.username AND disabled.groupname = 'daloRADIUS-Disabled-Users'";
if(!empty($_POST["searchPhrase"]))
{
$query .= 'WHERE (rc.id LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR rc.username LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR radusergroup.groupname LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR userinfo.firstname LIKE "%'.$_POST["searchPhrase"].'%" ';
}
$order_by = '';
if(isset($_POST["sort"]) && is_array($_POST["sort"]))
{
foreach($_POST["sort"] as $key => $value)
{
$order_by .= " $key $value, ";
}
}
else
{
$query .= 'ORDER BY rc.id DESC ';
}
if($order_by != '')
{
$query .= ' ORDER BY ' . substr($order_by, 0, -2);
}
if($records_per_page != -1)
{
$query .= " LIMIT " . $start_from . ", " . $records_per_page;
}
//echo $query;
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result))
{
$data[] = $row;
}
$query1 = "SELECT * FROM radcheck rc LEFT JOIN radusergroup ON rc.username=radusergroup.username LEFT JOIN userinfo ON rc.username=userinfo.username LEFT JOIN radusergroup disabled ON disabled.username=userinfo.username AND disabled.groupname = 'daloRADIUS-Disabled-Users'";
$result1 = mysqli_query($connection, $query1);
$total_records = mysqli_num_rows($result1);
$output = array(
'current' => intval($_POST["current"]),
'rowCount' => 10,
'total' => intval($total_records),
'rows' => $data
);
echo json_encode($output);
?>
users.php
<?php include ("inc/header.php");?>
<div class="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#"></a></li>
<li class="breadcrumb-item active">Users</li>
</ol>
</div>
</div>
<div class="container box">
<br />
<div align="left">
<button type="button" id="add_button" data-toggle="modal" data-target="#productModal" class="btn btn-info btn-lg">Add User</button>
</div>
<div class="table-responsive">
<table id="product_data" class="table table-bordered table-striped">
<thead>
<tr>
<th data-column-id="id" data-type="numeric">ID</th>
<th data-column-id="firstname">Customer Name</th>
<th data-column-id="username">User Name</th>
<th data-column-id="value">Password</th>
<th data-column-id="groupname">Groups</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
</table>
</div>
<?php include("inc/footer.php");?>
</div>
</body>
</html>
<?php include("inc/script_modal_user.php")?>
答案 0 :(得分:0)
我没有关闭WHERE附近的fetch.php中的括号(rc.id ...我关闭了括号,一切正常..谢谢
if(!empty($_POST["searchPhrase"]))
{
$query .= 'WHERE (rc.id LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR rc.username LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR radusergroup.groupname LIKE "%'.$_POST["searchPhrase"].'%" ';
$query .= 'OR userinfo.firstname LIKE "%'.$_POST["searchPhrase"].'%" )';
}