我有如下数据。我必须根据用户选择总结从7月开始到当前月份或任何月份的每个元素的每个月值。我不知道我是否应该在PHP中使用for或while循环。 希望有人能指出我正确的方向。
Element | Jan | Feb | Mar |Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dis
==============================================================================
A | 78 | 65 | 44 |67 | 76 | 88 | 66 | 65 | 87 | 90 | 56 | 70
B | 78 | 65 | 44 |67 | 76 | 88 | 66 | 65 | 87 | 90 | 56 | 70
C | 78 | 65 | 44 |67 | 76 | 88 | 66 | 65 | 87 | 90 | 56 | 70
查询
$sql2 = "Select element,
SUM(CASE WHEN Month = 'Jan' THEN total ELSE 0 END ) AS Jan,
SUM(CASE WHEN Month = 'Feb' THEN total ELSE 0 END ) AS Feb //until Dec
FROMtbl_ma GROUP BY element";
$rs2 = mysql_query($sql2);
$getRec2 = mysql_fetch_assoc($rs2);
打印
while ($row = mysql_fetch_assoc($rs2)) {
echo $row['Jan'] //until Dec
}
答案 0 :(得分:1)