【问题标题】: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 吗? 有什么想法吗?

【问题讨论】:

  • 你能发布实际执行的mysql查询吗?

标签: 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
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2017-06-06
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多