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 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 ?
MySQL UPDATE multiple columnsMySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.
To set all values in a single column MySQL query, you can use UPDATE command. The syntax is as follows. update yourTableName set yourColumnName =yourValue; To understand the above syntax, let us create a table.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With