In the code below, the if statement is evaluated as FALSE where I think it should be TRUE. What am I misunderstanding?
$sql = "SELECT * FROM LIVE";
$res = mysqli_query($con, $sql);
while ($result = mysqli_fetch_assoc ($res)){
var_dump($result['LIVE']); //string '1' (length=1)
echo $result['LIVE']. "<br>"; //1
}
$a = "1";
if($result['LIVE'] == $a){
echo "It is live!";
}
else {
echo "not live!"; //this gets echoed
}
I have tried all variations of quotes ', ", no quotes
AND changing the data and datatype for the column in the MYSQL table to BIT, CHAR, INT
AND CAST in PHP to BOOL and 'integer'
AND changing the operator eg =, ==, === and have also tried just typing into the if() instead of passing in $a as shown
AND $result = $result['LIVE'];
and passing in $result.
I have read PHP type comparison tables and PHP type juggling as well as all the other relative parts of the manual if(), while(), mysqli_fetch_array()
etc and can't solve this myself.
I am still learning PHP and I am sure it is an easy fix but I just can't see it.