select specific record based on year and month..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

select specific record based on year and month..

Post by kevin7 »

i've a data column in the table 2004-06-30 (define as date type in mysql)..
now, i want to retrive record that hv year 2004 and month 5 (May)...

the following is the code i've tried to make it work.. but failed..

Code: Select all

$comm = mysql_query("SELECT sal_comm, ord_id FROM sales WHERE emp_id='$emp_id' AND year(sal_date)='2004' AND month(sal_date)='5'");
.... how can i do that...

tq...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[mysql_man]BETWEEN[/mysql_man] I think..
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

@feyd, i don't think between will work here.
@kevin7, try adding mysql_error() to find whats wrong, because taht looks right to me....

Code: Select all

$comm = mysql_query("SELECT sal_comm, ord_id FROM sales WHERE emp_id='$emp_id' AND year(sal_date)='2004' AND month(sal_date)='5'") or die(mysql_error());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

true.. that can work too..
hmmm.. looks like bbcode for [mysql_man] isn't working.. bummer..
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

shucks! I don't think i has worked for quite some time now!
Post Reply