0

i am trying to create a table which calculate and add old balance with new balance but i get this when i run script.

Date       |Deposit|Expense|Balance |
26 July    |500    |       |500     |
25 July    |       |300    |200     |
22 July    |400    |       |600     |

i want to do this which show latest result first and calculation start from the end of table

Date       |Deposit|Expense|Balance |
26 July    |500    |       | 800    |
25 July    |       |300    | 300    |
22 July    |400    |       | 600    | (calculation start from the last row)

i am writing this code

while ($fetch = mysql_fetch_array($query)) {

$balance += $fetch[debit]-$fetch[credit];

echo "<tr class=\"" . $fetch[type]. "\">";
echo "<td>" . $fetch[date] . "</td>";
echo "<td>" . $fetch[debit] . "</td>";
echo "<td>" . $fetch[credit] . "</td>";
echo "<td>" . ($balance) . "</td>";
echo "</tr>";
}
DCoder
  • 12,962
  • 4
  • 40
  • 62
Ahmed
  • 43
  • 2
  • 7
  • What's the conceptual difference between this question and [your previous question](http://stackoverflow.com/questions/18288726/how-to-reverse-while-in-php), other than the gratuitous use of unrelated tags? [DevZer0's comment](http://stackoverflow.com/questions/18288726/how-to-reverse-while-in-php?lq=1#comment26830958_18288726) already answers what you need to do. – DCoder Aug 17 '13 at 13:19
  • 1
    Additionally, be advised that you are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use [a modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – DCoder Aug 17 '13 at 13:20

0 Answers0