Chartjs-PHP MySQL: count views per month for jQuery charts

1👍

You could use a query to group the visits by month:

SELECT COUNT(*), MONTH(date(timestamp)), YEAR(date(timestamp))
FROM table 
GROUP BY MONTH(FROM_UNIXTIME(date(timestamp)), YEAR(FROM_UNIXTIME(date(timestamp))

Which will return the number of visits, with the year and month they correspond to.

\EDIT\

To loop through and print each month’s value, use a mysqli_query and WHILE in PHP:

$query = mysqli_query($con, "THE QUERY ABOVE ^^");
while($row = mysqli_fetch_array($query {
echo $row['date(timestamp)'].",";
}

Leave a comment