我正在尝试从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");
}
答案 0 :(得分:2)
为什么不直接使用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 |
+---------+---------+-------+
WHERE
条款。答案 1 :(得分:0)
试试这个:
mysql_query("UPDATE Furniture SET Furniture = '". $totThisM ."' WHERE Item ='". $item ."' LIMIT 1");
修改强>
不正确的答案,请参阅评论以了解详情。