putrisakura Posted February 16, 2009 Share Posted February 16, 2009 Hello, below is the ouput I want. Date Description Debit Balance *notes 1/1/09 Jan 1000 1000 (1000-first data) 1/2/09 Feb 1500 2500 (1500+1000) 1/3/09 Mac 2000 4500 (2000+2500) I want to get the balance output like above. what i've done now is displaying the date, description and debit (from database). but I cannot display the balance output. I have no idea how to get sum of data value by row. Means in Row1=1000 so the balance is 1000.when it comes to row2=1500, the balance should become 2500(1000(row1)+1500(row2). The balance comes from debit(current row+previous row). Got it? any idea? Plz help me A.S.A.P. Link to comment https://forums.phpfreaks.com/topic/145425-how-to-sum-data-value-by-row/ Share on other sites More sharing options...
putrisakura Posted February 16, 2009 Author Share Posted February 16, 2009 <?php $query = "SELECT transaction, SUM(transaction) as balance FROM transaction GROUP BY ID"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['balance']; } ?> This it what I've try to get the balance output but the output is not what I want. The output that came out was : Date Description Debit Balance 1/1/09 Jan 1000 25002000 1/2/09 Feb 1500 25002000 1/3/09 Mac 2000 25002000 Plz help me solve this problem.. Link to comment https://forums.phpfreaks.com/topic/145425-how-to-sum-data-value-by-row/#findComment-763414 Share on other sites More sharing options...
printf Posted February 16, 2009 Share Posted February 16, 2009 Please show the real table scheme, thank you! Link to comment https://forums.phpfreaks.com/topic/145425-how-to-sum-data-value-by-row/#findComment-763440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.