我有一个包含多行的表格。我想更新每一行,直到我以先入先出(FIFO)顺序离开我的金额余额。示例表:
id value balance
row 1 1000 1000
row 2 2000 2000
row 3 1500 1500
row 4 1000 1000
对于此表格,我得到2500(文本框$topcfcacc
的值)。
现在我想支付第一行的全部值,因为它小于收到的金额。然后是第二行,直到我收到的金额为0。
$topcfcacc = $_POST['pcfc'];
$selectpcfc = "SELECT * FROM `pcfc_disbursed` where status = 0 order by pcfc_disbursed_id asc";
$pcfc_result = mysqli_query($connection, $selectpcfc);
if (mysqli_num_rows($pcfc_result) > 0)
{
$num_rows = mysqli_num_rows($pcfc_result);
for ($i=0;$i<$num_rows;$i++)
{
$pcfcrows = mysqli_fetch_assoc($pcfc_result);
$disbursed_id = $pcfcrows['pcfc_disbursed_id'];
$disbursed = $pcfcrows['disbursed_usd'];
$usdbalance = $pcfcrows['balance_usd'];
$usdpaid = $pcfcrows['paid_usd'];
if($topcfcacc > $usdbalance)
{
$updatepcfc= "UPDATE `pcfc_disbursed` SET `balance_usd`=0,`paid_usd`=$usdbalance,`status`=1 WHERE pcfc_disbursed_id = $disbursed_id";
$pcfc_update_result = mysqli_query($connection, $updatepcfc);
}
else
{
$updatepcfc= "UPDATE `pcfc_disbursed` SET 'balance_usd`=0,`paid_usd`=$usdbalance,`status`=1 WHERE pcfc_disbursed_id = $disbursed_id";
$pcfc_update_result = mysqli_query($connection, $updatepcfc);
}
}
}