php - update sum of columns in a sql table -


i have table named resources following columns:

ress1  ress2  prod1  prod2  

i've tried code indicated in following links, i'm still stuck...

how find sum of multiple columns in table in sql server 2005?

auto update sum of rows & columns in table

sql how update sum of column on group in same table

i want run script update ress1 = ress1 + prod1 , same ress2. want update column sum of column , corresponding column, doing every rows table.

here code seems easy me, not working...

$sql    = "select * ro_map"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_assoc($result)){ $new_a = $row['a'] + $row['c']; $new_b = $row['b'] + $row['d'];  "update ro_map set = '$new_a',b = '$new_b'"; }  

ah...really sorry, guys :d use mysql (with wampp server , heidisql). , running code don t give me error ( if($conn->$sql == true) give me true... solved! cool, all, i've learned :)

i think you're over-complicating it. if understand correctly, can in 1 transaction:

update    resources set       ress1 = ress1 + prod1,           ress2 = ress2 + prod2 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -