PHP:警告:mysqli_num_rows()要求参数1为mysqli_结果,字符串为
我正在尝试按照以下查询获取数据PHP:警告:mysqli_num_rows()要求参数1为mysqli_结果,字符串为,php,mysql,mysqli,Php,Mysql,Mysqli,我正在尝试按照以下查询获取数据 $query= "SELECT * FROM residential "; if($type!=""){ $query.=" AND type='$type'"; } if($unit_type!=""){ $query.=" AND unit_type='$unit_type'"; }
$query= "SELECT * FROM residential ";
if($type!=""){
$query.=" AND type='$type'";
}
if($unit_type!=""){
$query.=" AND unit_type='$unit_type'";
}
if(($min_price!="") && ($max_price!="")){
$query.=" AND price BETWEEN '$min_price' AND '$max_price' ";
}
if(($min_bedrooms!="") && ($max_bedrooms!="")){
$query.=" AND bedrooms BETWEEN '$min_bedrooms' AND '$max_bedrooms'";
}
if($query==FALSE){
echo mysqli_error($connect);
die;
}
$result= mysqli_query($connect,$query);
这就是我使用它的方式
<div class="row">
<?php if(mysqli_num_rows($query)>0):?>
<?php while($row= mysqli_fetch_assoc($query)):
print_r($row);
die;
?>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="row property-listing">
<div class="col-md-6 col-sm-6 col-xs-12">
<img src="images/1.png" class="img-responsive full-width">
</div>
<div class="col-md-6 col-sm-6 col-xs-12 property-desc">
<h3>AED<br/> <?php echo $row['price'];?></h3>
<h5>Unit Type: <?php echo $row['unit_type'];?></h5>
<h5>Available for :<?php echo $row['type'];?></h5>
<h5>Location :<?php echo $row['area'];?></h5>
<h5>Bedrooms :<?php echo $row['bedrooms'];?></h5>
</div>
</div>
</div>
<?php endwhile;?>
<?php else:
echo 'We found no record for your search criteria ';
echo '<a href="index.html">Refine Search</a>'
?>
<?php endif;?>
</div>
AED
单位类型:
适用于:
地点:
卧室:
这就是我得到的错误
(!)警告:mysqli_num_rows()希望参数1为
mysqli_结果,给定字符串
正在发布和获取的值是正确的,但查询有问题,请帮助我解决
谢谢只需更改此代码
$query=“从住宅中选择*”;
进入
$query=“从住宅中选择*1”;
并更改此代码
到
您正在向mysqli_num_rows()
和mysqli_fetch_assoc()
添加查询字符串,当它需要mysqli_result
时-在您的情况下,变量$result$query
是您的查询字符串,而不是您的结果集。因此只需使用$result
<?php if(mysqli_num_rows($result)>0):?>
<?php while($row= mysqli_fetch_assoc($result)):
在Sql查询中不包括WHERE子句
如果要将查询与第一个sql查询的其他参数连接起来,请在第一个sql字符串中添加一个WHERE子句,如下所示
$query=“选择*来自住宅,其中表\u id!=0”代码>
这里的表\u id是表的主键。这将是连接查询的好方法。
之后,您可以添加其他值来连接查询,如
if($type!=""){
$query.=" AND type='$type'";
}
因此,您的最终查询如下所示
SELECT * FROM residential WHERE table_id!=0 AND type='$type'
接下来,您要将$query
传递给mysqli\u num\u行,您应该为此传递$result