gpt4 book ai didi

php - MYSQL INT 加法

转载 作者:行者123 更新时间:2023-11-29 08:10:29 26 4
gpt4 key购买 nike

我正在尝试从 mysql 获取 INT 值并进行添加,最后更新数据库。不过这个好像没有更新?我该如何解决这个问题?

$resultSecond = mysql_query("SELECT * FROM Furniture");
while($lineSecond = mysql_fetch_array($resultSecond)) {
$item = $lineSecond["Item"];
$janD = $lineSecond["January"];
$febD = $lineSecond["February"];
$marD = $lineSecond["March"];
$pastVals = $lineSecond["yearSale"];
$totalCT = $lineSecond["monthSale"];

$totThisM = ($janD + $febD + $marD + $pastVals + $totalCT);
mysql_query("UPDATE Furniture SET Furniture = '".$totThisM."' WHERE Item ='$item' LIMIT 1");
}

最佳答案

为什么不直接使用 MySQL?

UPDATE `Furniture`
SET `Furniture` = (`January`+`February`+`March`+`yearSale`+`monthSale`)

测试数据

+---------+---------+-------+
| number1 | number2 | total |
+---------+---------+-------+
| 1 | 5 | 0 |
| 2 | 3 | 0 |
+---------+---------+-------+

然后我运行我的查询;

UPDATE table SET total = (`number1`+`number2`);

表格已更新;

+---------+---------+-------+
| number1 | number2 | total |
+---------+---------+-------+
| 1 | 5 | 6 |
| 2 | 3 | 5 |
+---------+---------+-------+

注释

  • 删除了 CodeBird 注释后的 WHERE 子句。
  • 根据 Ravinder 的评论调整查询

关于php - MYSQL INT 加法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21724046/

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