hayesb2 Posted April 9, 2008 Share Posted April 9, 2008 This is likely simple for most but I'm learning... I have a mysql database, and in the table "products" is a column for "products_price". How do I write the php code to update all of the prices values in the database so they are 15% higher? Link to comment https://forums.phpfreaks.com/topic/100361-update-price/ Share on other sites More sharing options...
paul2463 Posted April 9, 2008 Share Posted April 9, 2008 $query = "UPDATE tablename SET pricecolumn = pricecolumn * 1.15"; Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513175 Share on other sites More sharing options...
hayesb2 Posted April 9, 2008 Author Share Posted April 9, 2008 Thank you and what if I wanted to subtract 15%? Last question Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513195 Share on other sites More sharing options...
paul2463 Posted April 9, 2008 Share Posted April 9, 2008 you would do the same maths for adding 15% to do the subtraction $query = "UPDATE tablename SET pricecolumn = pricecolumn - 15%"; //however you do that math Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513197 Share on other sites More sharing options...
hayesb2 Posted April 9, 2008 Author Share Posted April 9, 2008 The thing is I dont know the syntax to do minus 15% Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513201 Share on other sites More sharing options...
paul2463 Posted April 9, 2008 Share Posted April 9, 2008 thats maths syntax to make that happen and I dont know what it is it may be $query = "UPDATE tablename SET pricecolumn = pricecolumn - ((pricecolumn/100)*15)"; Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513206 Share on other sites More sharing options...
fenway Posted April 9, 2008 Share Posted April 9, 2008 Or "= ROUND( 0.85 * pricecolumn, 2 )" Link to comment https://forums.phpfreaks.com/topic/100361-update-price/#findComment-513351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.