crEA-tEch
12-05-2008, 07:10 AM
PHP+mySQL - Struggling with BETWEEN statement with year and date variables... Help!
Hey guys,
I'm running a mySQL query but I've looked everywhere and can't find a way of doing it..
Here's my form:http://www.thestreetlyschool.co.uk/temp/PHP2.jpg
Here's the table structure:http://www.thestreetlyschool.co.uk/temp/PHP1.jpg
And here's how the results will be displayed:http://www.thestreetlyschool.co.uk/temp/PHP3.jpg
I've tried many ways to try and list all the entries from a daterange.
E.g. From January 2008 to December 2008 etc etc..
This is what I've got so far:
PHP Code:
$queryÂÂ*= "SELECT * FROM depu_usage WHERE YEAR(datetime) BETWEEN `$year-$month` AND `$yeara-$montha` AND department_id = `$department_id` ORDER BY datetime";
I know it's not great! But I've tried all the normal ways I can think of.
I keep getting errors like "Unknown column '2008-09' in 'where clause'" and syntax errors.
Any help would be appreciated!!
Cheers,
crE
__________________<<< Please see Forum Guidelines for signature setup. >>>
Hey guys,
I'm running a mySQL query but I've looked everywhere and can't find a way of doing it..
Here's my form:http://www.thestreetlyschool.co.uk/temp/PHP2.jpg
Here's the table structure:http://www.thestreetlyschool.co.uk/temp/PHP1.jpg
And here's how the results will be displayed:http://www.thestreetlyschool.co.uk/temp/PHP3.jpg
I've tried many ways to try and list all the entries from a daterange.
E.g. From January 2008 to December 2008 etc etc..
This is what I've got so far:
PHP Code:
$queryÂÂ*= "SELECT * FROM depu_usage WHERE YEAR(datetime) BETWEEN `$year-$month` AND `$yeara-$montha` AND department_id = `$department_id` ORDER BY datetime";
I know it's not great! But I've tried all the normal ways I can think of.
I keep getting errors like "Unknown column '2008-09' in 'where clause'" and syntax errors.
Any help would be appreciated!!
Cheers,
crE
__________________<<< Please see Forum Guidelines for signature setup. >>>
