I am trying to to create an array based on the results from sum values based on the distinct values from another column
I have these two columns Month and Lessons. In the column month is the month name when the lessons were given (January, February...). In the column lessons I have values like (12,7,6,9,11, etc.)
$month_values = 19,6,20;
$sth = $db->prepare("SELECT DISTINCT month FROM acc where month!=''");
$result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
$months = json_encode($result);
SELECT month, SUM(lessons) FROM lessons_by_month GROUP BY month ORDER BY MONTH(STR_TO_DATE(month,'%M')) ASC
The above query will output you sum of lessons in the calendar month order.