I am working with line chart from amchats demo and I need to get data for each month from previous years and also that of this year from a field in my database. I've tried some queries like getting values for each month in a year by iterating through the months.
But, that's not what I need.
for ($i=12; $i > 0 ; $i--) {
$query = $conn->prepare("SELECT date_inserted FROM communications WHERE YEAR(date_inserted) = YEAR(CURRENT_DATE - INTERVAL $i MONTH) AND MONTH(date_inserted) = MONTH(CURRENT_DATE - INTERVAL $i MONTH)");
}
Btw, I need to get something like: the table below where value is the total count of data found in that month
2012-01-31, Value: 20
2012-02-28, Value : 53
...
2019-04-16, value : 32