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
https://forums.phpfreaks.com/topic/288412-records-from-a-month/
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.