PHP MySQL remove quantity -


i met situation when need import values quantity spended many times qty.

eg. have table product material

id    type    quantity    spent 1     1       10           0 2     1       100          0 

now spent 20 qty of material once , need update field spent this

id    type    quantity    spent 1     1       10           10     <--- 0 left 2     1       100          10     <--- 90 left 

or spend 8 qty first 20 qty, table needs

first - spent 8

id    type    quantity    spent 1     1       10           8       <--- 2 left 2     1       100          0       <--- 100 left 

second - spent 20

id    type    quantity    spent 1     1       10           10       <--- 0 left 2     1       100          18       <--- 72 left 

so need separate spended material quantity avaible , reduce till limit reduce other 1 avaible qty.

what best way php?

please appreciated, thank you!

update `tablename` set `spent` = 10, `quantity` = `quantity` - `spent` `id` = 1 

note id , spent fields fields have example values (10 , 1 can changed, depends on you)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -