开发者

Update doesn't work as should be in MySQL

开发者 https://www.devze.com 2022-12-14 10:12 出处:网络
echo $totalprice; echo \"<br/>\"; echo $shortfall; echo \"<br/>\"; echo $unitprice; echo \"<br/>\";
 echo $totalprice;
echo "<br/>";
echo $shortfall;
echo "<br/>";
echo $unitprice;
echo "<br/>"; 

I got

24 80 0.3

Then the following command was executed.

// update query

However, only

total_price

was changed(became 0.00) while other values like

unit_price

stay unchanged. But other values like

unit_price

should be changed.

Total_price

is

开发者_如何学编程

unsigned when total_price-pricebalance is done, it becomes 0.00. So does it refuse to subtract $totalprice? Any idea?


Why are you using ANDs in your UPDATE query?

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());

Or with better readability:

UPDATE piecework SET total_price = total_price - pricebalance + $totalprice,
                     quota = quota - shortfall + $shortfall,
                     shortfall = $shortfall,
                     unit_price = $unitprice,
                     pricebalance = $totalprice
...
0

精彩评论

暂无评论...
验证码 换一张
取 消