Answer the question
In order to leave comments, you need to log in
Highcharts display visitors for the last month?
Good evening comrade friends.
There is a need to display site visitors for the last month (today -1 month)
The problem is that I did not have visitors on the site every day, and the query skips days when they were not. And you need to show 0 if that day was empty. Or you can somehow implement it on HC so that empty values \u200b\u200bare substituted.
Here is the SQL
select left(date_visited, 10) as `date`, count(id) as `count` from visitors
where date_visited between '$dateStart' and '$dateEnd'
group by left(date_visited, 10)
Answer the question
In order to leave comments, you need to log in
I came up with this solution, but maybe someone knows more elegant and correct
$period = new DatePeriod(
new DateTime(date('Y-m-d', strtotime('now -30 days'))),
new DateInterval('P1D'),
new DateTime(date('Y-m-d'))
);
$visitorStats = [];
foreach($period as $date) {
$visitorStats[$date->format('Y-m-d')] = 0;
}
// sql query ...
foreach($dbRows as $row) {
$visitorStats[$row->date] = $row->count;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question