Search Posts

How can I put sql count value on a variable?

I construct a code wherein it will count records where reservation_status = ‘WAITING’. If the total number of waiting is >= 1, then it will show the records and perform the claiming of reservations. Else it will echo “The Unclaimed Reservations List is Empty”.

This is my code:

  <?php
  $countsql = mysqli_query($conn,"SELECT count(*) FROM reservations WHERE reservation_status = 'WAITING';");
  $count = mysqli_num_rows($countsql);
  if ($count >= 1){          
  $select = mysqli_query($conn,"SELECT * FROM reservations WHERE reservation_status = 'WAITING';");
  while($userrow = mysqli_fetch_array($select)){
        $reservationid=$userrow['reservation_id'];
        $startdate=$userrow['reservation_start_date'];
        $enddate=$userrow['reservation_end_date'];
        $cname=$userrow['customer_name'];
        $rroom=$userrow['reserved_room'];

                echo $rroom;?>
<a href="claimreservations.php?reservation_id=<?php echo $reservationid; ?>" onclick="return confirm('Are you sure to claim this reservation?');"/>CLAIM RESERVATION</a>
  <?php}}else if($count = 0){
  echo "The Unclaimed Reservations List is Empty".}
?>

Now, I don’t know why does it show both the records and this error message:

Notice: Object of class mysqli_result could not be converted to int in
C:xampphtdocssystemadmin pagesReservationsview.php on line 6

Source: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *