gpt4 book ai didi

php - while 循环内的 update 语句

转载 作者:行者123 更新时间:2023-11-29 22:16:03 24 4
gpt4 key购买 nike

我正在编写一个程序,需要插入另一个表中的计算值。

例如用户输入“2”

首先,用户将搜索“所需数量”栏下的所有记录。并且搜索完后,程序会自动将所有需要的数量乘以“2”

我使用了更新语句,因为该表的默认值为零

这是我的代码:

$num = $_POST['qtytoorder']; 
$sql = "select qtyrqrd from bom_inventory where boardmodel ='$boardname'";
$result =@mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$qty = $row['qtyrqrd'];
$res = $qty * $num;
echo $res;
//insert new records for qtyneeded via update statement
$insert ="update bom_inventory set qtyneeded='$res', qty2complete =$res where boardmodel ='$boardname'";
@mysql_query($insert,$connect)or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
}

我的代码在运行时没有错误,但我的问题是我只得到最后相乘的数量。我想插入所有相乘的数量。

最佳答案

经过一番讨论之后,这就是我猜的结果

$num = $_POST['qtytoorder']; 
$sql = "select id, qtyrqrd from bom_inventory where boardmodel ='$boardname'";
$result =@mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$qty = $row['qtyrqrd'];
$res = $qty * $num;
$id = $num['id'];
echo $res;
//insert new records for qtyneeded via update statement
$insert ="update bom_inventory set qtyneeded='$res', qty2complete =$res where id ='$id'";
@mysql_query($insert,$connect)or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
}

很高兴我能帮助你:)

关于php - while 循环内的 update 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199582/

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