可能重複:
How to sort by previous date in database?如何排序和添加我的數據庫記錄?
我想要做的就是選擇從MySQL是一個日期記錄,然後從我的數據庫記錄我需要添加這是按日期排序
量我的數據庫記錄:
amount | date
2.0 | 2011-10-01
1.4 | 2011-10-02
2.6 | 2011-10-01
2.3 | 2011-10-02
4.4 | 2011-10-01
5.6 | 2011-10-03
6.3 | 2011-10-01
我想在我的界面中顯示:
amount | date
2.0 | 2011-10-01
2.6 | 2011-10-01
4.4 | 2011-10-01
6.3 | 2011-10-01
---------------------------
15.3 | 2011-10-01
1.4 | 2011-10-02
2.3 | 2011-10-02
----------------------------
3.7 | 2011-10-02
5.6 | 2011-10-03
----------------------------
5.6 | 2011-10-03
我的代碼(它不工作):
$Current = date("Y-m-d" ,strtotime("now"));
$query=mysql_query("SELECT * from item where date < $Current order by date");
while($re=mysql_fetch_array($query)){
echo $total = $total + $re['amount'];
echo $re['date'];
}
這是不是能很好地工作?
感謝
這可以通過查詢與聚合函數的數據庫中進行,見http://dev.mysql.com/doc/refman/5.0/en/group-by-functions。 html – hakre