I am trying to check if result returned by database is zero but it always falls to zero following is my code
if(isset($_POST['cust_id'])){
$cust_id = $_POST['cust_id'];
$stmt = $connect->prepare("SELECT DISTINCT send_stamp, message, time, status FROM `chat` WHERE cust_id=?");
$stmt->bind_param('i', $cust_id);
}
else if(isset($_POST['receiverid'])) {
$receiverid = $_POST['receiverid'];
$stmt = $connect->prepare("SELECT DISTINCT send_stamp, message, time, status FROM `chat` WHERE receiverid=?");
$stmt->bind_param('i', $receiverid);
}
if($stmt->execute()){
$data = array();
if($stmt->num_rows ==0){
$data[] = array(
'message'=> 'No messages found',
'status'=>0,
);
}
else{
$result = $stmt->get_result();
while ($row =mysqli_fetch_array($result)) {
$data[] = array(
'message'=> $row['message'],
'time'=> $row['time'],
'status'=> $row['status'],
);
}
}
}
echo json_encode( $data);
Please help me to figure out this situation . Thanks
echo exitwhich condition is execute