我搜索过类似的问题,我可以找到类似的问题。但似乎没有人回答我的问题。我是php的新手,无法找到我的查询返回FALSE的原因。 我的错误: mysqli_num_rows()期望参数1为mysqli_result,第17行[Directory]中给出的布尔值
我的代码:
<?php
$con=mysqli_connect("fdb17.biz.nf","XXXX", "XXXX","2337985_searchengine", "3306");
$testdb=mysqli_select_db($con,"searchengine");
if(isset($_POST['search_query'])){
$search_query=mysqli_real_escape_string($con,htmlentities($_POST['search_query']));
echo "<div class=\"searchText\">Search</div><hr/>";
$search_query_x=explode(" ",$search_query);
$query="";
foreach($search_query_x as $search_each){
if($search_query_x)
$query="keywords LIKE '%$search_each%'";
else
$query.="AND keywords LIKE '%$search_each%'";
}
$query="SELECT * FROM search WHERE $query";
$result=mysqli_query($con,$query);
$nr=mysqli_num_rows($result);
if($nr==0){
echo "Sorry, there are no matching result for <b>$search_query</b><br>
1.Try more general words.<br>
2.Try different words with similar meaning.<br>
3.Please check your spelling.<br>";
}
else
{
echo "$nr results found !<p>";
while($rr=mysqli_fetch_assoc($run))
{
$title=$rr['title'];
$desc=$rr['desc'];
$url=$rr['url'];
echo"
<div class='width: 400px;'>
<div class='title'><a href='$url'><b>$title</b></a></div>
<div class='desc'>$desc</div>
<div class='url'>$url</div>
</div><br>
";
}
}
}
?>
如果有人能发现那个很棒的问题。
在前几条评论之后更新,但仍然遇到同样的问题:
<?php
$con=mysqli_connect("XXXX","XXXX", "XXXX","XXXX", "XXXX");
$testdb=mysqli_select_db($con,"searchengine");
if(isset($_POST['search_query'])){
$search_query=mysqli_real_escape_string($con,($search_each));
echo "<div class=\"searchText\">Search</div><hr/>";
$search_query_x=explode(" ",$search_query);
$query="";
foreach($search_query_x as $search_each){
if($query == '')
$query="keywords LIKE %$search_each%";
else
$query="AND keywords LIKE %$search_each%";
}
$query="SELECT * FROM search WHERE $query";
$result=mysqli_query($con,$query);
$nr=mysqli_num_rows($result);
if($nr==0){
echo "Sorry, there are no matching result for <b>$search_query</b><br>
1.Try more general words.<br>
2.Try different words with similar meaning.<br>
3.Please check your spelling.<br>";
}
else
{
echo "$nr results found !<p>";
while($rr=mysqli_fetch_assoc($run))
{
$title=$rr['title'];
$desc=$rr['desc'];
$url=$rr['url'];
echo"
<div class='width: 400px;'>
<div class='title'><a href='$url'><b>$title</b></a></div>
<div class='desc'>$desc</div>
<div class='url'>$url</div>
</div><br>
";
}
}
}
?>
答案 0 :(得分:0)
感谢您的帮助,现在解决了问题。我认为主要的罪魁祸首是一个区分大小写的Mysql表,以及你们纠正的一些错误。