gpt4 book ai didi

PHP:在从另一个表获取数据时更新产品表数量

转载 作者:行者123 更新时间:2023-11-29 02:42:28 25 4
gpt4 key购买 nike

我在更新从 invoiceitem 表中获取的数据以更新产品表 quantity 时遇到问题。

这个问题只是第一个记录在我的循环中更新

请帮助我将多个项目值更新到数据库。

这是我的代码:

<?php



$stuid = $_GET['id'];
global $con;

$stu_query = "SELECT * FROM invoiceorder INNER JOIN invoiceorderitem ON invoiceorder.InvoId = invoiceorderitem.InvoId WHERE invoiceorder.InvoId ='$stuid'";

$stu_run = mysqli_query($con,$stu_query);


while($sorows = mysqli_fetch_array($stu_run)){
$Date = $sorows['Date'];
$SalesPerson = $sorows['SalesPerson'];
$Telephone = $sorows['Telephone'];
$Customer = $sorows['Customer'];
$CurrentPayment = $sorows['CurrentPayment'];
$Balance = $sorows['Balance'];

$Item_Id = $sorows['Item_Id'];
$ItemDescription = $sorows['ItemDescription'];
$UnitPrice = $sorows['UnitPrice'];
$Quantity = $sorows['Quantity'];
$SubTotal = $sorows['SubTotal'];
$Total = $sorows['Total'];

$sea_res = mysqli_query($con, "SELECT * FROM bincard WHERE BinId = $Item_Id");

while ($resresults = $sea_res->fetch_assoc()){

$BinId = $resresults['BinId'];
$ItemName = $resresults['ItemName'];
$QtyBalance = $resresults['QtyBalance'];
$QtyIssued = $resresults['QtyIssued'];

//chech this
$newqty=0;
$isuqty=0;

$newqty =$QtyBalance - $Quantity;
$isuqty = $QtyIssued + $Quantity;
$insert_query = "UPDATE bincard SET QtyBalance='$newqty',QtyIssued='$isuqty' WHERE BinId = $Item_Id";
}
if ($con->query($insert_query) === TRUE)
{
echo"<script>alert(' Updated Successfully')</script>";
echo"<script>window.open('invoiceprint.php','_self')</script>";
} else
{
echo "Error: " . $insert_query . "<br>" . $con->error;
}



$con->close();
}







?>

最佳答案

if ($con->query($insert_query) === TRUE) 放在 while 循环中。如果它只更新一条记录,那么 $sea_res->fetch_assoc() 中只有一条记录。

while ($resresults = $sea_res->fetch_assoc()){

$BinId = $resresults['BinId'];
$ItemName = $resresults['ItemName'];
$QtyBalance = $resresults['QtyBalance'];
$QtyIssued = $resresults['QtyIssued'];

//chech this
$newqty=0;
$isuqty=0;

$newqty =$QtyBalance - $Quantity;
$isuqty = $QtyIssued + $Quantity;
$insert_query = "UPDATE bincard SET QtyBalance='$newqty',QtyIssued='$isuqty' WHERE BinId = $Item_Id";

if ($con->query($insert_query) === TRUE)
{
echo"<script>alert(' Updated Successfully')</script>";
echo"<script>window.open('invoiceprint.php','_self')</script>";
} else{
echo "Error: " . $insert_query . "<br>" . $con->error;
}
}

关于PHP:在从另一个表获取数据时更新产品表数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48748776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com