Sql query for month

i want data for a specific month only

$month = date('m');
$query = "SELECT * FROM staff_attend WHERE rep_id=$idd  AND MONTH(comp_date)=$month";

this give data of all months in database
Request help please

$query = "SELECT * FROM staff_attend WHERE rep_id=$idd  AND MONTH(comp_date)=MONTH(CURRENT_DATE())";

this also does not help

When a WHERE clause incorrectly matches all values, it is generally because of a datatype or data conversion problem (when a number is involved in a comparison, strings are converted to numbers) and results in a comparison of zero with zero, which is a true value.

What is the datatype and format of the comp_date column?

Also, because you are putting values directly into the sql query statement (you should use a prepared query instead), something about the value in $idd could be short-circuiting the WHERE clause preventing the AND … part from mattering.

What does var_dump($query); show?

Sponsor our Newsletter | Privacy Policy | Terms of Service