Merdok Posted January 5, 2011 Share Posted January 5, 2011 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 More sharing options...
Maq Posted January 5, 2011 Share Posted January 5, 2011 Yes, that is correct but 6% is .06. Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155268 Share on other sites More sharing options...
Merdok Posted January 5, 2011 Author Share Posted January 5, 2011 LOL told you I was terrible at maths, thank you Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155269 Share on other sites More sharing options...
Merdok Posted January 5, 2011 Author Share Posted January 5, 2011 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? Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155274 Share on other sites More sharing options...
Maq Posted January 5, 2011 Share Posted January 5, 2011 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) Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155286 Share on other sites More sharing options...
BLaZuRE Posted January 6, 2011 Share Posted January 6, 2011 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. Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155481 Share on other sites More sharing options...
Merdok Posted January 6, 2011 Author Share Posted January 6, 2011 Thankfully I backed the DB up first It worked a treat. Thanks guys! Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155663 Share on other sites More sharing options...
Maq Posted January 6, 2011 Share Posted January 6, 2011 Thankfully I backed the DB up first It worked a treat. Thanks guys! Yes, that's always a good idea. I've seen many get burned because they didn't backup, myself included. Link to comment https://forums.phpfreaks.com/topic/223495-update-values-in-mysql-by-percentage/#findComment-1155674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.