我遇到这个问题,当我搜索一个单词时,它不会出现并且会弹出此错误
警告:mysqli_fetch_array()期望参数1为mysqli_result,在213行的C:\ xampp \ htdocs \ public_html \ filterdata.php中给出的布尔值)。
仅在过滤之前显示表格
<?php
include("auth_admin.php");
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `lcho_dengue_activities` CONCAT(`id`, `month`, `year`, `dengue_ind1`) where `month`= '".$valueToSearch."'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `lcho_dengue_activities`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "lcho_login");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<form action="filterdata.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>Month</th>
<th>Year</th>
<th>dengue_ind1</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['month'];?></td>
<td><?php echo $row['year'];?></td>
<td><?php echo $row['dengue_ind1'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
//while($row = mysqli_fetch_array($search_result))
是我的第213行
我尝试将$search_result
更改为$query
,并且发生相同的错误。
答案 0 :(得分:0)
该查询失败并返回false
将此内容放在mysqli_query()
之后,以查看发生了什么情况。
if (!$filter_Result) {
printf("Error: %s\n", mysqli_error($connect));
exit();
}
有关更多信息: