【发布时间】:2016-09-02 09:03:36
【问题描述】:
我正在使用数据表,它有一个内置搜索(如果你这么称呼它的话),现在我在我的表列表中搜索性别时遇到问题,因为每当我搜索“男性”时,男性和女性出现在列表中。我会怎么做,如果我搜索男性,它将只过滤性别“男性”。但是如果我搜索女性,女性呢?如果我没有尝试任何东西,我很抱歉,因为我真的不知道。虽然我尝试搜索,但是那些与我有同样问题的人没有我理解的答案,所以我只是在尝试也许你们可以帮助我。如果你不能因为我没有尝试过任何东西,我理解。但我仍然希望。提前谢谢你!
数据库名称 - db_seq
表名 - 配置文件
表格列 - 姓名、性别、用户名、密码
编辑:我的代码
<?php include('dbcontroller.php');
$sql = "SELECT name, gender FROM profile ORDER by name ASC";
$res = mysqli_query($conn,$sql)or die(mysqli_error());
?>
<table id="batchList" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Gender</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Gender</th>
</tr>
</tfoot>
<tbody>
<?php
while ($row = mysqli_fetch_array($res)) {
$name = $row['name'];
$gender = $row['gender'];
?>
<tr>
<td><?php echo $name;?></td>
<td><?php echo $gender;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
mysqli_close($conn);
?>
<script>
$(document).ready(function() {
$('#batchList').DataTable();
} );
</script>
【问题讨论】:
-
什么数据库,什么表结构,样本数据
-
您是否了解“男性”是“女性”的最后四个字母,因此这取决于您的搜索代码究竟是如何工作的?所以请出示该代码。
-
是的,我明白这一点。我不能给你搜索发生的部分,因为它是来自数据表的 jquery,而且它不是那么容易理解(至少对我来说)希望你理解我的观点@CodeCaster
-
如果你不能显示你的代码,没有人可以回答这个问题。对于此列,您只需要完全匹配,而不是“LIKE”查询。没有任何代码就不能说更多。
-
如果只是
$("#yourTable").DataTable()那也没关系。无论如何它looks like you should simply disable smart searching on the relevant column or apply an anchored regex filter。另请参阅jQuery DataTables - Filter column by exact match。
标签: php search mysqli datatables