I have searched this site and the rest of the internet for a bit but I am having a hard time figuring this out.
//Connecting to database using $con and then getting percentage of items that have pass
$query = mysqli_query($con, 'SELECT 100 *
SUM(exterioralignment = pass)/COUNT(exterioralignment) FROM door1');
//passing the resource to an array
$row=mysqli_fetch_assoc($query);
//printing the array to check if everything worked well
echo $row;
When I enter the below into MySQL it gives me the required result but the above code does not print anything
SELECT 100 * SUM(exterioralignment = pass)/COUNT(exterioralignment) FROM door1
The error I get in the logs is mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\
but my understanding is that mysqli_query is a result and not a boolean. As you can tell I am inexperienced in this so please try to be detailed with your answers.
Thank you
EDIT: I used $a="PASS"; $a=mysqli_real_escape_string($con, $a); $query = mysqli_query($con, 'SELECT 100 * SUM(exterioralignment ("$a"))/COUNT(exterioralignment) AS total FROM door1');
But the returned answer is 0 instead of 80 as it is supposed to be. If I copy paste the query to Mysql and put "pass" instead of $a it gives me 80 so I think something is going wrong when I am escaping the $a string