【问题标题】:Update doesn't work as should be in MySQL更新在 MySQL 中不能正常工作
【发布时间】:2009-12-22 01:54:06
【问题描述】:
echo $totalprice;
echo "<br/>";
echo $shortfall;
echo "<br/>";
echo $unitprice;
echo "<br/>";
我明白了
24 80
0.3
然后执行以下命令。
//更新查询
但是,只有
total_price
已更改(变为 0.00),而其他值如
单价
保持不变。但其他值,如
单价
应该改变。
总价格
是
无符号
当 total_price-pricebalance 完成时,它变为 0.00。
那么它拒绝减去 $totalprice 吗?
有什么想法吗?
【问题讨论】:
标签:
php
sql
mysql
database
【解决方案1】:
为什么在 UPDATE 查询中使用 ANDs?
mysql_query("update piecework set total_price=total_price-pricebalance+$totalprice, quota=quota-shortfall+$shortfall, shortfall=$shortfall, unit_price=$unitprice, pricebalance=$totalprice where piecework_id='$pieceworkid' and publisher=$memberid and (pricebalance-$totalprice)>=0")or die(mysql_error());
或者具有更好的可读性:
UPDATE piecework SET total_price = total_price - pricebalance + $totalprice,
quota = quota - shortfall + $shortfall,
shortfall = $shortfall,
unit_price = $unitprice,
pricebalance = $totalprice
...