Jump to content

mysql query and php issue


marksie1988

Recommended Posts

i have the below function but the mysql query doesn't seem to work, i want it to select all of the specific users logged miles (userid='$userid') and then select the ones between a date range and add them up.

 

so if todays date was 05/08/08 it would remove 2629744 from the unix timestamp (30 days) and then this would be the date range from 5/07/08 to 05/08/08 once the date range is set it would find the rows with the userid and the date range and then add all the results miles together.

 

below is the code please help, currently the mysql query just adds all of the miles in that date range

 

   function MilesDoneMTD($userid, $date){
   					$curdate = $date - (2629744);
		      $mdytd = "SELECT sum(miles) FROM mileage WHERE userid='$userid' AND datedone BETWEEN '".$curdate."' AND '".$date."' GROUP BY userid";
			  $mdytdr = mysql_query($mdytd); 
			  $rows = mysql_fetch_array($mdytdr);
			  echo "Miles Done MTD: ".$rows['sum(miles)']."";
   }

Link to comment
https://forums.phpfreaks.com/topic/118525-mysql-query-and-php-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.