MySql update field value based on other field values -


im trying create query following:

here table:

id     total     paid     own       status ------------------------------------------------ 1      100.00    100.00   100.00    0 

and here query:

$total = 50; update cart table set paid = $total, status = case when $total >= own 1 else 2 end; 

the idea if total amount of field "total" equal or greater amount in field "own" update field "status" 1, otherwize 2.

im not sure if can 1 query, or need update cart table, pull results, perform calculations , update again.

try this:

update cart table set paid = $total, status = if($total >= own, 1, 2) id = 1; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -