Je hebt een paar problemen:
- De indexen naar
$row
tussen aanhalingstekens moeten staan, bijv.$row['name']
anders krijg je veel "Undefined constant" waarschuwingen; $row['Jan']
is de juiste manier om de maandelijkse gegevens op te halen, u moet dat voor elk van de andere maanden repliceren;- vervang
$avgGrade
met$row['AVG']
- Ik weet niet zeker wat je probeert te bereiken met
<td class = "gScore-<?php echo $row[Jan]; ?>"></td>
wil je eigenlijk
<td class = "gScore"><?php echo $row[Jan]; ?></td>
- je moet de
-- repeat for May to November
rijen naar de zoekopdracht, d.w.z.
$result = $db->query("SELECT name,
COALESCE(AVG(CASE WHEN mth = 1 THEN PTS END), 0) AS Jan,
COALESCE(AVG(CASE WHEN mth = 2 THEN PTS END), 0) AS Feb,
COALESCE(AVG(CASE WHEN mth = 3 THEN PTS END), 0) AS Mar,
COALESCE(AVG(CASE WHEN mth = 4 THEN PTS END), 0) AS Apr,
COALESCE(AVG(CASE WHEN mth = 5 THEN PTS END), 0) AS May,
COALESCE(AVG(CASE WHEN mth = 6 THEN PTS END), 0) AS Jun,
COALESCE(AVG(CASE WHEN mth = 7 THEN PTS END), 0) AS Jul,
COALESCE(AVG(CASE WHEN mth = 8 THEN PTS END), 0) AS Aug,
COALESCE(AVG(CASE WHEN mth = 9 THEN PTS END), 0) AS Sep,
COALESCE(AVG(CASE WHEN mth = 10 THEN PTS END), 0) AS Oct,
COALESCE(AVG(CASE WHEN mth = 11 THEN PTS END), 0) AS Nov,
COALESCE(AVG(CASE WHEN mth = 12 THEN PTS END), 0) AS `Dec`,
AVG(PTS) AS AVG
FROM (
SELECT name, PTS AS PTS, MONTH(STR_TO_DATE(DATE, '%a %b %e %H:%i:%s %Y')) AS mth
FROM data
) d
GROUP BY name");