Jump to content

update values in mysql by percentage


Merdok

Recommended Posts

OK I'm sure this is a very easy question but I am terrible with mathematics and I can't get my head around this one.

 

I have an ecommerce store and I want to increase all the prices on the site by 6%, is this the correct way to do it?

 

UPDATE shop_prod SET price = price * 0.6

 

I'm sure the maths is wrong there and that is where I'm falling down I expect.

Link to comment
https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/
Share on other sites

Hmm... I tried this but it didn't seem to work properly

 

 

UPDATE shop_prod SET price = price * .06

 

the prices ended up being reduced instead, for example a product that was £407 became around £24

 

What did I do wrong?

 

Hmm... I tried this but it didn't seem to work properly

 

 

UPDATE shop_prod SET price = price * .06

 

the prices ended up being reduced instead, for example a product that was £407 became around £24

 

What did I do wrong?

 

 

Sorry, that would set the prices to 6% of their original value.  This should be what you want:

 

UPDATE shop_prod SET price = price + (price*.06)

If you need help restoring prices then marking them up:

 

price / 0.06 * 1.06

 

price / 0.06 restores the orig * 0.06 error

 

*1.06 does the 6 percent markup

 

By the way, using order of operations on the above post, you get (price * .12) since multiplication comes first.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.