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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.