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>";
}