我尝试了这些代码,但是他们给了我一条错误信息
"警告:mysqli_fetch_array()要求参数1为mysqli_result,第67行/home/ubuntu/workspace/php_html_table_data_filter.php中给出布尔值。调用堆栈:0.0004 237240 1. {main}()/ home / ubuntu / workspace / php_html_table_data_filter.php:0 0.0011 237976 2. mysqli_fetch_array()/ home /ubuntu /workspace / php_html_table_data_filter.php:67"
这是我尝试过的代码。我认为在concat的查询语句中会出现错误,因为当我运行时,整个数据库出现但是当我点击搜索时,错误消息将会出现。 我真的希望有人能够帮助我:)
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `users` WHERE CONCAT(`id`, `fname`, `lname`, `age`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `users`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "test_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>
<form action="php_html_table_data_filter.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['fname'];?></td>
<td><?php echo $row['lname'];?></td>
<td><?php echo $row['age'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body>
</html>