选择并更新表,然后在值为零时停止选择
问题描述:
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,
- Select and update table until buyer amount to pay gets to zero then stop.
- 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.
答
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();