0

我正在尝试创建一个表来计算旧余额并将其与新余额相加,但是当我运行脚本时我得到了这个。

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

我想这样做,首先显示最新结果,计算从表格末尾开始

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

我正在写这段代码

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

0 回答 0