I have a MySQL query:
SELECT COUNT(*) AS total, DATE_FORMAT(event.serverTime,'%Y-%m-%d') AS sdate
FROM event
WHERE
event.serverTime >= :startDate
AND event.serverTime <= :endDate
GROUP BY sdate;
Which correctly returns something like:
2011-08-10 => 5
2011-08-15 => 6
However, I would like to also get the dates where there was 0 counts. So assuming startDate is 2011-08-10 and endDate is 2011-08-15, I would see:
2011-08-10 => 5
2011-08-11 => 0
2011-08-12 => 0
2011-08-13 => 0
2011-08-14 => 0
2011-08-15 => 6
I am using PHP so in theory I could do some complex looping and fill up the gaps somehow, but I am wondering if there is a better solution?
Note that if no good MySQL solution exist, I’m also open to good PHP solutions
You need to make a table with dates and join against that.
Now do the following query