I have a table which stores a php timestamp as a interger. I need to access this data by date and year. I can grab the year and match it with a column row that exists within the table but need to obtain the month name from the timestamp.
Code so far
$query="SELECT * FROM archive_agent_booking
WHERE agent_id='$account_no'
AND (MONTHNAME(comp_date)='$month' AND year='$year' AND details='')
ORDER BY order_time";
unfortunately this is returning nothing.
comp_date is the column that contains the timestamps
you need to convert it to date first using
FROM_UNIXTIMEAs a sidenote, the query is vulnerable with
SQL Injectionif the value(s) came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.