Sie haben ein paar Probleme:
- Die Indizes zu
$row
müssen in Anführungszeichen gesetzt werden, z.$row['name']
andernfalls erhalten Sie viele "Undefinierte Konstanten"-Warnungen; $row['Jan']
der richtige Weg ist, um die monatlichen Daten abzurufen, müssen Sie das für jeden der anderen Monate replizieren;- ersetze
$avgGrade
mit$row['AVG']
- Ich bin mir nicht sicher, was Sie damit erreichen wollen
<td class = "gScore-<?php echo $row[Jan]; ?>"></td>
willst du eigentlich
<td class = "gScore"><?php echo $row[Jan]; ?></td>
- Sie müssen den
-- repeat for May to November
hinzufügen Zeilen zur Abfrage, z. B.
$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");