I'm writing a php script which will update my sql filed
with some math.
Should I make a query to get the filed value开发者_StackOverflow中文版 first then update the filed or there is something to update the filed with in the query it self
here is the math
$sum = 5 ;
$filed = $filed +(($filed * 100) / $sum) ;
This how the math goes with in the PHP. Is there any way to get this math done by the query it self ?
Assuming filed
is the name of a column in your table, you can do the math right inside the MySQL query, without involving PHP:
UPDATE table SET filed = (filed + ((filed * 100) / 5) WHERE some_condition;
Just be sure to set the appropriate conditions in your WHERE
clause so you don't update rows you don't intend to update.
精彩评论