我正在尝试设置一个处理程序,这样当我得到0个结果时,它会显示一条消息,说找不到结果。我有点工作,但我现在面临两个问题。
当我得到0个结果时,它确实显示没有找到结果,但它也显示以下错误:
警告:mysqli_query()要求参数2为字符串,对象在第74行的/customs/b/6/d/herculesdjs.co.uk/FETCH.PHP中给出
第74行是这样的:
$fetch_row = mysqli_query($con,$result);
这是完整的脚本减去连接信息$城市由下拉框定义。经过测试,效果良好:
$result = mysqli_query($con,
sprintf("SELECT * FROM `SouthYorkshire` WHERE `city_id` = '%s'",
preg_replace("[^0-9]","", $city)));
// Handle Null Results.
$fetch_row = mysqli_query($con,$result);
$numrows = $fetch_row[0];
if($numrows==0)
{
echo "<div id='"NoResults'">";
echo "There are no clubs in this area, Why not come back another day. Know of one in this area? Why not submit it via Contact Us.";
echo "</div>";
}
while($row = mysqli_fetch_array($result))
{
echo "<div id='"Results'">";
echo "<div id='"theclub'">";
echo "<div class='"ClubName'">";
echo $row['EstName'];
echo "</div><br>";
echo "<div class='"Location'">";
echo $row['EstAddress2'];
echo "</div>";
echo "<br>";
echo "<div id='"website'"><a href='"#'"><img src='"photos/more-info.png'" width='"75'" height='"25'"/></a> <a href='"" . $row['EstWebsite'] ."'" target='"_blank'"><img src='"photos/visit-website-button.png'" width='"75'" height='"25'" /></div></a></div>";
echo "<br>";
}
echo "</div>";`
我遇到的另一个问题是,如果数据库中有结果,它不会显示警告。它显示找到的结果,但也显示"没有俱乐部"消息。
有什么建议吗?
天知道为什么您认为这是获取查询返回的记录数的正确方法:这完全是无稽之谈。
您应该去掉$fetch_row
,转而使用mysqli_num_rows()
:
$numrows = mysqli_num_rows($result);