我以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