I want to know how can I foreach a sql count statement depending on its status. When I tried to echo it, all statuses turned into number 1. I want to put it inside a loop instead of doing the statement five times.
<?php
$statuses = array("In-process", "Approved", "Draft", "Approved" , "Rejected");
foreach ($statuses as $stat) {
$stmt = $db->prepare(
"SELECT COUNT(status) FROM `m2_exception_requests`
WHERE created_by= ? and status = ?"
) or die($db->error);
$stmt->bind_param("ss", $user_id , $stat);
$stmt->execute();
$result = $stmt->store_result();
if ($stat = 'In-process') {
$Inprocess1 = $result;
}
if ($stat = 'Approved') {
$Approved1 = $result;
}
if ($stat = 'Draft') {
$Draft1 = $result;
}
}