Possible Duplicate:
How to sort by previous date in database?
I want to do is select from mysql which is previous date records then from my database records I need to add the amount which is sort by date
my database records:
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
What I want to display in my interface:
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
my code (it not work):
$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'];
}
Isn’t this can work nicely ?
thanks
Have you looked into MySQL’s WITH ROLLUP option.
Something like this