Du har et par problemer:
- Indekserne til
$row
skal anføres i anførselstegn f.eks.$row['name']
ellers vil du få en masse "Udefineret konstant" advarsler; $row['Jan']
er den korrekte måde at hente de månedlige data på, skal du replikere det for hver af de andre måneder;- erstat
$avgGrade
med$row['AVG']
- Jeg er ikke sikker på, hvad du forsøger at opnå med
<td class = "gScore-<?php echo $row[Jan]; ?>"></td>
vil du faktisk have
<td class = "gScore"><?php echo $row[Jan]; ?></td>
- du skal tilføje
-- repeat for May to November
rækker til forespørgslen, dvs.
$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");