0

Hello I am trying to look after content of Selected query... but however the error appears:

Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\e-catalog\index.php on line 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> &#8377; <?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       
    }
}
?>

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sarowar
  • 9
  • 1
  • 1
  • 2

1 Answers1

-3

The query either returned no rows or has error, thus FALSE is returned.

Change it to

if(!$queryfire || mysqli_num_rows($queryfire) == 0){
    $num = mysqli_num_rows($queryfire);
}

Return Values Returns TRUE on success or FALSE on failure. For SELECT, SHOW, DESCRIBE or EXPLAIN mysqli_query() will return a result object.

Credit:PHP & MySQL: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given