Anda memiliki beberapa masalah:
- Indeks ke
$row
harus diapit tanda kutip mis.$row['name']
jika tidak, Anda akan mendapatkan banyak peringatan "Konstanta tidak ditentukan"; $row['Jan']
adalah cara yang benar untuk mengambil data bulanan, Anda perlu menirunya untuk setiap bulan lainnya;- ganti
$avgGrade
dengan$row['AVG']
- Saya tidak yakin apa yang ingin Anda capai dengan
<td class = "gScore-<?php echo $row[Jan]; ?>"></td>
apakah kamu benar-benar menginginkannya
<td class = "gScore"><?php echo $row[Jan]; ?></td>
- Anda perlu menambahkan
-- repeat for May to November
baris ke kueri yaitu
$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");