我想了解为什么会发生这种错误,有时我会以相同的方式呈现我的$ result变量,并且不会发生错误。我试图谷歌搜索原因,而不是运气。所以我有示例代码,其中发生以下错误。
mysqli_fetch_assoc()期望参数1为mysqli_result,第26行给出布尔值
有人可以帮我纠正一下,并提供有效的解释吗?
<?php
include 'connect.php';
include 'header.php';
//first select the category based on $_GET['cat_id']
if($_SERVER['REQUEST_METHOD'] != 'get')
{
$sql = "SELECT
cat_id,
cat_name,
cat_description
FROM
categories
WHERE
cat_id = " . mysqli_real_escape_string($link, $_GET['cat_id']);
$result = mysqli_query($link, $sql);
if(!isset($result))
{
echo 'The category could not be displayed, please try again later.';
}
else
{
//display category data
while($row = mysqli_fetch_assoc($result))
{
echo '<h2>Topics in ′' . $row['cat_name'] . '′ category</h2>';
}
//do a query for the topics
$sql = "SELECT
topic_id,
topic_subject,
topic_date,
topic_cat
FROM
topics
WHERE
topic_cat = " . mysqli_real_escape_string($link,$_GET['topic_cat']);
$result = mysqli_query($link, $sql);
if(!isset($result))
{
echo 'The topics could not be displayed, please try again later.';
}
else
{
if(mysqli_num_rows($result)== 0)
{
echo 'There are no topics in this category yet.';
}
else
{
//prepare the table
echo '<table border="1">
<tr>
<th>Topic</th>
<th>Created at</th>
</tr>';
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td class="leftpart">';
echo '<h3><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><h3>';
echo '</td>';
echo '<td class="rightpart">';
echo date('d-m-Y', strtotime($row['topic_date']));
echo '</td>';
echo '</tr>';
}
}
}
}
}
include 'footer.php';
?>