Multiple UPDATEs in one SQL statement

wxdqz

New Member
Hello,

I have a case where I would like to do multiple UPDATEs or INSERTs into a table.

such as:
UPDATE rates SET price = \'11\'
WHERE property_id = 18 AND season_id = 4;

UPDATE rates SET price = \'22\'
WHERE property_id = 18 AND season_id = 5;

UPDATE rates SET price = \'33\' WHERE property_id = 18 AND season_id = 6;
and so on....

In PHP, I could execute these queries one at a time in a while loop, and it seems to be fast enough, but I would much rather build a query string containing everything in the loop and then only call mysql_query() once. If I try this, I get:

You have an error in your SQL syntax near \'; UPDATE rates SET price = \'22\' WHERE property_id = 18 AND season_id = 5; UPDATE\' at line 1

By the way, if I paste the query into phpMyAdmin this query executes just fine, so it must be possible.

Thanks for any help.
 
Back
Top