【问题标题】:Select and update table then stop selecting when value is zero选择并更新表,然后在值为零时停止选择
【发布时间】:2018-01-24 21:23:28
【问题描述】:

即为同一类型的产品向多个客户支付的金额为 20,000 美元。 客户一 12,000 美元, 客户二 $3,000, 客户二 5,000 美元。 总共是 20,000 美元。

我希望当买家点击购买产品并且它们可用时,

  1. 选择并更新表格,直到买家支付的金额为零然后停止。
  2. 计算他应该支付的行数并更新他的行。

我试过了

$qry=mysqli_query($link,"Select sum(selleramount) from sellertable Where buyer product>0");
$asum=$row[0];
($row=mysqli_fetch_array($ry));
foreach ($qry as $row) {
    $balance=$buyeramount-$asum;
    mysqli_query($link,"insert into buyertable (amount,seller_id,) values ('$amount_to_payseller','$sellertopayid')");
    mysqli_query($link,"update sellertable set seller amount='$balance'");
}

我试过了,但没有成功。我有想法,但我不知道如何去做。

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    我没有你的数据来正确测试它,但 Transaction 方法可能在这里工作。例子!

    $qry=mysqli_query($link,"Select sum(selleramount) from sellertable Where buyer product>0");
    $asum=$row[0];
    $mysqli->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
    ($row=mysqli_fetch_array($ry));
    foreach ($qry as $row) {
        $balance=$buyeramount-$asum;
        mysqli_query($link,"insert into buyertable (amount,seller_id,) values ('$amount_to_payseller','$sellertopayid')");
        mysqli_query($link,"update sellertable set seller amount='$balance'");
    }
    $mysqli->commit();
    $mysqli->close();
    

    【讨论】:

    • 感谢您的回答。请问上面的解决方案会做什么。
    • 实际上,事务和提交基本上将挂起事务,完成后,通过移动记录结束指针以包含新更新来提交。因此,如果总数失败,您可以添加回滚。
    猜你喜欢
    • 1970-01-01
    • 2014-08-26
    • 2014-09-01
    • 1970-01-01
    • 2021-01-04
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    相关资源
    最近更新 更多