你好,我正在尝试照顾选定查询的内容...但是出现错误: 警告 :mysqli_num_rows()期望参数1为mysqli_result,布尔值在 C:\ xampp \ htdocs \ e-catalog \ index.php 在线 30
<div class="row">
<?PHP
$con = mysqli_connect('localhost','root', '');
mysqli_select_db($con,'ecatalog');
$query = " SELECT `name`, `image`, `price`, `discount` FROM `eproduct` order by id ASC ";
$queryfire = mysqli_query($con, $query);
$num = mysqli_num_rows($queryfire);
if($num > 0){
while($product = mysqli_fetch_array($queryfire)){
?>
<div class="col-lg-3 col-md-3 col-sm-12">
<form>
<div class="card">
<h6 class="card-title bg-info text-white p-2 text-uppercase"> <?php echo
$product['name']; ?> </h6>
<div class="card-body">
<img src="<?php echo
$product['image']; ?>" alt="phone" class="img-fluid mb-2" >
<h6> ₹ <?php echo $product['price']; ?><span> (<?php echo $product['discount']; ?>% off) </span> </h6>
<h6 class="badge badge-success"> 4.4 <i class="fa fa-star"> </i> </h6>
<input type="text" name="" class="form-control" placeholder="Quantity">
</div>
<div class="btn-group d-flex">
<button class="btn btn-success flex-fill"> Add to cart </button> <button class="btn btn-warning flex-fill text-white"> BUy Now </button>
</div>
</div>
</form>
</div>
<?php
}
}
?>
答案 0 :(得分:-1)
查询不返回任何行或有错误,因此返回FALSE。
将其更改为
if(!$queryfire || mysqli_num_rows($queryfire) == 0){
$num = mysqli_num_rows($queryfire);
}
返回值 成功返回TRUE,失败返回FALSE。对于SELECT,SHOW,DESCRIBE或EXPLAIN,mysqli_query()将返回结果对象。
信用:PHP & MySQL: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given