php mysql help

Discussion in 'PHP' started by red_fiesta, Apr 29, 2007.

  1. #1
    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):
     
    red_fiesta, Apr 29, 2007 IP
  2. dzysyak

    dzysyak Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can select all data where date field is between last day of previous month and fist one on the next one.
     
    dzysyak, Apr 29, 2007 IP
  3. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    red_fiesta, Apr 29, 2007 IP
  4. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4

    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 # ??
     
    red_fiesta, Apr 29, 2007 IP
  5. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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):
     
    red_fiesta, Apr 29, 2007 IP
  6. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I always use unix timestamp and perform calculations with it. It eliminates the pains :p
     
    manilodisan, Apr 29, 2007 IP