ProblemHelpPlease Posted January 17, 2011 Share Posted January 17, 2011 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 More sharing options...
thescientist Posted January 17, 2011 Share Posted January 17, 2011 probably SQL. It looks like you would want to sort it by a certain date. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted January 17, 2011 Author Share Posted January 17, 2011 I could do it with SQL if I had a way of looping through a date range and pulling out the day, month and year for each run of the loopEdit: Think I might have cracked it. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted January 17, 2011 Author Share Posted January 17, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.