Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the error that I got when I executed it
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\Clinic\Staff\chart.php on line 172

This is my code:
<?PHP
$connect = mysqli_connect("localhost", "root", "", "testingfolder"); 
    $query3 = "SELECT consultationstatus_diagnosis, count(*) as number FROM tbl_consultationstatus WHERE month(consultationstatus_date)=1 GROUP BY consultationstatus_diagnosis ORDER BY count(*) DESC LIMIT 1 UNION ALL SELECT consultationstatus_diagnosis, count(*) as number FROM tbl_consultationstatus WHERE month(consultationstatus_date)=2 GROUP BY consultationstatus_diagnosis ORDER BY count(*) DESC LIMIT 1;";
?>


What I have tried:

PS: I'm doing this because I'm going to graph the data in a line graph.
I need to gather the highest cases per month for forecasting reasons. I'd be grateful if you could assist me with my difficulty.
Posted
Updated 11-Nov-21 2:55am

The error message is telling you that the previous command failed, as explained at PHP: mysql_query - Manual[^].
 
Share this answer
 
Comments
Mark Limuel Fernando 11-Nov-21 8:41am    
when I didn't add the union it runs perfectly any idea how to combine two MySql Executions?
Try taking out the Group By in the top sql Unions don't like that. Group at the end when all the data is collected. If it still breaks, try removing the LIMIT 1 to test.

SQL
SELECT consultationstatus_diagnosis, count(*) as number 
FROM tbl_consultationstatus 
WHERE month(consultationstatus_date)=1 
ORDER BY count(*) DESC 
LIMIT 1 
UNION ALL 
SELECT consultationstatus_diagnosis, count(*) as number 
FROM tbl_consultationstatus 
WHERE month(consultationstatus_date)=2 
GROUP BY consultationstatus_diagnosis 
ORDER BY count(*) DESC 
LIMIT 1;
 
Share this answer
 
Comments
Mark Limuel Fernando 11-Nov-21 11:16am    
the problem is the ORDER BY
snorkie 11-Nov-21 13:04pm    
Right,should have had my coffee first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900