我有一个查询:
SELECT MONTH(tgl) AS month, SUM(jumlahA) AS A, SUM(jumlahB) AS B
FROM tabel where YEAR(tgl)='2002' GROUP BY MONTH(tgl) order by 1;
结果是:
month A B
----------------------
1 85 0
2 38 0
9 34 23
问题是如何在 PHP 中完整显示一年(12 个月)的数据,其中月份没有数据将 0 放入 A 和 B。实际上我想创建带有月轴的条形图(jan、feb、...、des )
更新
这是我的一些PHP代码:
echo "<categories>\n";
echo "<category name='Jan' />\n";
echo "<category name='Feb' />\n";
echo "<category name='Mar' />\n";
echo "<category name='Apr' />\n";
echo "<category name='Mei' />\n";
echo "<category name='Jun' />\n";
echo "<category name='Jul' />\n";
echo "<category name='Agu' />\n";
echo "<category name='Sept' />\n";
echo "<category name='Okt' />\n";
echo "<category name='Nop' />\n";
echo "<category name='Des' />\n";
echo "</categories>\n";
echo "<dataset seriesname='Hulu' color='AFD8F8'>";
$strQuery="SELECT MONTH(tgl) AS month, SUM(jumlahA) AS A, SUM(jumlahB) AS B FROM tabel where YEAR(tgl)='2002' GROUP BY MONTH(tgl) order by 1";
$hasil=mysql_query($strQuery);
while ($data = mysql_fetch_array($hasil)) {
echo "<set value='".$data[1]."' />";
}
echo "</dataset>";