Currently I have a system where a PHP script logs some information (time and “sid”) of a visit when the page is loaded.
I then use:
SELECT *
FROM (
SELECT COUNT(*), time
FROM visit
WHERE sid = $sid
GROUP BY time
ORDER BY time DESC
LIMIT 14
) AS abc
ORDER BY time ASC
to get the results from the last fortnight in reverse order.
The problem with this query is that on days with no visits I do not get the result: 0, [time], but instead nothing. What would I do to get a result of zero on those days? Is it even possible in MySQL or would I have to process it with PHP?
Any help greatly appreciated!
You have to use a second table containing all dates (or use a subquery like below). So extend the subquery for table
ttillCURDATE()-13for having last 14 days.