There is a table with the goods. id, title, price . A lot of data, and you need to write a script that will increase the price as a percentage.

For example: Goods with a price of 1000. It is necessary to increase by 10%. Accordingly, it is necessary that this all work on the MySQL side.

I did this: I get the data, then I drive them in a cycle, increasing the price and write to the database. Not very correct. And how to create a query that will increase all values ​​on the MySQL side?

    1 answer 1

    https://stackoverflow.com/a/3466/5006740

    if you just want to upgrade all products by 10 percent:

     UPDATE `table` SET `price` = `price` + (`price`/100)*10; 

    # 10 is your variable percentage, insert it from the script

    • price = price / 100 * 110; or price = price * 1.10; - Visman
    • Well, maybe the percentage he will change. - strangeqargo
    • So what? Higher mathematics there with interest? :) - Visman
    • let him calculate it somehow) you have a good answer too - strangeqargo