Jump to content

adding values based on dates


ProblemHelpPlease

Recommended Posts

I have a database with a total field with values like (199.99) and a date field with values like (2010-06-23 14:50:04)I want to display a list of dates with all the prices that have that date added up, so if 3 dates matched it might say450.50 - 2010-06-23 I dont know if this needs to be done in PHP or in the SQL query.Any Ideas?

Link to comment
Share on other sites

Managed to do it with the following

$endDate = '2010-12-31';$startDate = '2010-06-22';$newDate = $startDate;while($newDate != $endDate){$newDate = date('Y-m-d',strtotime(date("Y-m-d", strtotime($newDate)) . " +1 day"));$pieces = explode("-", $newDate);$get_total = mysql_query("SELECT SUM(total) FROM table1 WHERE MONTH(outdate) = '$pieces[1]' AND YEAR(outdate) = '$pieces[0]' AND DAYOFMONTH(outdate) = '$pieces[2]'");$getrow = mysql_fetch_array($get_total);echo $newDate . " - " . "£" . number_format($getrow['SUM(total)'], 2) . "<br>";}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...