Reputation: 149
I'm trying to bring the INT values from mysql and do a addition and finally update the database. But this doesn't seem to do update? How can I fix this?
$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");
}
Upvotes: 0
Views: 59
Reputation: 11375
Why not just use MySQL?
UPDATE `Furniture`
SET `Furniture` = (`January`+`February`+`March`+`yearSale`+`monthSale`)
+---------+---------+-------+
| number1 | number2 | total |
+---------+---------+-------+
| 1 | 5 | 0 |
| 2 | 3 | 0 |
+---------+---------+-------+
And I run my query;
UPDATE table SET total = (`number1`+`number2`);
And the table is updated;
+---------+---------+-------+
| number1 | number2 | total |
+---------+---------+-------+
| 1 | 5 | 6 |
| 2 | 3 | 5 |
+---------+---------+-------+
WHERE
clause after comment from CodeBird.Upvotes: 2
Reputation: 2560
Try this :
mysql_query("UPDATE Furniture SET Furniture = '". $totThisM ."' WHERE Item ='". $item ."' LIMIT 1");
Edit
Not the right answer, see comments for details.
Upvotes: 0