我以php的形式创建了搜索过滤功能。从表中获取来自mysql的数据。所有查询和其他人写得很好。但搜索功能不起作用。PHP搜索过滤功能不起作用
<?php
require_once 'init.php';
include 'header.php';
include 'navigation.php';
if(isset($_POST['search'])){
$valSearch = $_POST['searchButton'];
$query = "SELECT * FROM mainTable WHERE CONCAT ('id','commandName','commandDesc','status') LIKE '%".$valSearch."%'";
$featured = filterTable($query);
}else{
$query = "SELECT * FROM mainTable";
$featured = filterTable($query);
}
function filterTable($query){
$connect = mysqli_connect("localhost","root","","linuxcommanddictionary");
$filter_result = mysqli_query($connect,$query);
return $filter_result;
}
?>
<form action = "index.php" method="post">
<div class="container">
<h3>Linux Fedora OS</h3><hr>
<button type="submit" name ="searchButton" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
<input type="text" name = "search" class="form-control" placeholder="Хайх үгээ бичнэ үү">
<div class="col-md-12">
<div class="row">
<table class="table table-bordered">
<thead>
<th>ID</th>
<th>Command Name</th>
<th>Command Description</th>
<th>Status</th>
</thead>
<tbody>
<?php while($result = mysqli_fetch_assoc($featured)): ?>
<tr>
<td><?=$result['id']; ?></td>
<td><?=$result['commandName']; ?></td>
<td><?=$result['commandDesc']; ?></td>
<td><?=$result['status']; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</form>
<?php
include 'footer.php';
?>
</body>
</html>
这是数据库结构。
create table if not exists mainTable(
id int auto_increment,
commandName varchar(255),
commandDesc varchar(255),
status int(2),
primary key(id)
)
它不工作是不是从开发者的一个很好的解释
3-转。你会得到什么错误? – Akintunde007
也似乎你需要通过你的连接变量作为你的过滤器表函数的全局变量 – Akintunde007
没有出现任何错误。 – ARLEQUINA