Chathurika Chathurika - 5 months ago 10
SQL Question

Count the sum of raw in mysql table

I want to get sum value of "number_of_date" in emp_leaves table, according to particular employee ID and make some variable to assign it's value. Following is my query.

$resultOfcount= mysql_query("SELECT SUM(number_of_date) AS number_of_date FROM emp_leaves WHERE emp_id='$userID' && leave_category='$category");
$value=mysql_fetch_array($resultOfcount);

$value1=$value['number_of_date'];





But it makes some error which is

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ..





How can I fix it, Please help.

Answer

You are missing a ' at the end of the WHERE part

$resultOfcount= mysql_query("SELECT SUM(number_of_date) AS number_of_date FROM emp_leaves WHERE emp_id='$userID' && leave_category='$category'");

Thatswhy the query fails and returns false