Hoàng Trung Hiếu Hoàng Trung Hiếu - 4 years ago 97
SQL Question

Can not echo results of SELECT COUNT - FIXED

i am trying to echo the result of the SQL SELECT COUNT but it seems doesn't work for me, can anyone of you help me?
The error show that

mysql_fetch_array expects parameter 1 to be resources, boolean given

This is my sql

$query = ("SELECT COUNT(*) AS total FROM `errors` WHERE `sta` = 0");
$result = mysql_query($query);
$count = mysql_fetch_array($result);
echo $count['total'];

Answer Source

Try to following code:

 $query = ($con, "SELECT COUNT(*) AS total FROM errors WHERE sta = 0");
 $count = mysql_fetch_assoc($query);
 echo $count['total'];

Hope will help you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download