I have a database table and one of the fields is a date These dates are stored lile 03/07/2007 how do i in php just get the results for certain months... something like <? $strSQL = "SELECT Player_Name, p.Player_ID from trainingattendance t, player p WHERE training date=" (how do i pass here a month into a field that is a date); $Conn=mysql_connect(***); mysql_select_db("**",$Conn); $result = mysql_query($strSQL); $row = mysql_fetch_assoc($result); ?> Code (markup):
You can select all data where date field is between last day of previous month and fist one on the next one.
Is that the best way, do you have any example of code? $strSQL = "SELECT Player_Name, p.Player_ID from trainingattendance t, player p WHERE Training_Date between ... and ... "; how do i write the first of the current month and last day of current month in php so it changes when we go to a new month.
something like... $strSQL5 = "SELECT Player_Name, p.Player_ID from trainingattendance t, player p WHERE p.Player_ID=t.Player_ID and Training_Date between '01/".date('m/y')."' and '31/".date('m/y')."'"; Code (markup): what am i supposed to use for the date ' or # ??
ok this returns the player ids but not the trainingdates, why? <? $strSQL5 = "SELECT distinct Training_Date, Player_ID from trainingattendance WHERE Training_Date between '01/".date('m/y')."' and '31/".date('m/y')."'"; $Conn=mysql_connect("localhost","*****","*****"); mysql_select_db("*****",$Conn); $result5 = mysql_query($strSQL); ?> <? print $strSQL5; ?><br> <? while($row5 = mysql_fetch_assoc($result5)){ print $row5['Player_ID']; print $row5['Training_Date']; ?> <? } mysql_close($Conn); ?> Code (markup):