How to update multiple rows with one query

•

It’s not so hard to update multiple rows with only one query. All we need to do is to use MySQL “CASE” functionality.

mysql_query(" update category
    set price = 
    case 
    when name = 1 then '$_POST[price1]'
    when name = 2 then '$_POST[price2]'
    when name = 3 then '$_POST[price3]'
    end
    WHERE name in (1,2,3)");

Leave a Reply

Your email address will not be published. Required fields are marked *