I have been trying this code for some time now, and I cant figure it out.
<?php
$link = mysqli_connect("localhost", "h4g54453g5234", "23j4hbjh243v535", "3j45hv6j3h45v645");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = 'SELECT COUNT(*) FROM users WHERE phone=9876543210 AND status=1';
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
echo "" . $row['COUNT(*)'] . "";
}
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
The result of above code will be "4", because the column "status" only 4 data with the number "1".
now I can use echo $row['COUNT(*)']; to display the number "4".
But, I want to show results like following echo "$status1; (which will show "4") echo "$status2; (which will show "4") echo "$status3; (which will show "2")
How can I do that? Using the above code, I can only show the result of status column with value 1.