Jump to content

records from a month


Aero77

Recommended Posts

I'm having a fuel score list and I would like users to choose a month and they can see the average fuel consumption that month. Right now I have a working code that shows the average for the last 30 days, but I have added a drop down menu with all the months inside. How can I change the query depending on the month they choose ?

 

If they choose April the value would be 4, but I dont know how to pick only records from April when the dates in the database are like 2014-04-15 format. How can I do this ? I will also have to add a year selector box of course.

 

Hope anyone can help. This is my current code

	$dx = date('Y-m-d', strtotime('today - 30 days'));
	
		$query = "SELECT m.username, m.id, 10 * SUM(d.liter) / (MAX(d.km) - MIN(d.km)) as AvgFuel 
  FROM members AS m
LEFT OUTER
  JOIN diesel AS d
    ON d.userid = m.id
   AND d.dato >= '$dx' 
WHERE d.liter > 0
GROUP
    BY m.id ORDER BY AvgFuel ASC";
	
		$sql=$oDB->prepare($query);
		$sql->execute();
		$row = $sql->fetchAll();
    return $row;
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.