douping7105 2017-08-16 16:17
浏览 13
已采纳

选择并更新表,然后在值为零时停止选择

I.e amount to pay more than one client for same type of products is $20,000. Client One $12,000, Client Two $3,000, Client Two $5,000. Which to total is $20,000.

I want when buyer clicks to purchase for a product and they are available,

  1. Select and update table until buyer amount to pay gets to zero then stop.
  2. Count number of rows of those he should pay and update his row.

I have tried

$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'");
}

I have tried but its not working out. I have the idea but how to go about what I want I don't know.

  • 写回答

1条回答 默认 最新

  • dqyy38265 2017-08-16 16:29
    关注

    I dont have your data to test it properly, but the Transaction method may work here. Example!

    $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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大