Forum Moderators: coopster

Message Too Old, No Replies

MySQL increasing numeric values within a table?

mysql database functions - sums -

         

population

4:31 am on Apr 10, 2004 (gmt 0)

10+ Year Member



I have a database table which contains prices. I want to increase the price of every product in my store by 5%. Without manually editing every single record, is there a command I can execute which will automatically go in, retrieve the current prices, calculate the new prices and then update the column (or create the new value in a new column)?

Thanks!

Rick

bobnew32

5:45 am on Apr 10, 2004 (gmt 0)

10+ Year Member



$sql= "select * from table";
$result= mysql_query($sql);
while($row= mysql_fetch_array($result))
{

$update= "update table set value= value * '0.05' + value where id= '$row[id]'";
$res= mysql_query($update);

}

population

7:11 am on Apr 10, 2004 (gmt 0)

10+ Year Member



Thank you very much. I will give it a try!

Rick

brucec

5:53 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



or SET price=price*1.05 would work :)