Reputation: 81
$query = "UPDATE TABLE1
SET (row1 = '$val1' WHERE row5 = '$someid' AND active = 'yes')
, (row1 = '$val2' WHERE row5 = '$someid' AND active = 'yes')
, (row1 = '$val3' WHERE row5 = '$someid' AND active = 'yes')";
mysql_query($query);
This query does nothing. I can not update data.
What am I doing wrong?
Upvotes: 0
Views: 214
Reputation: 98901
Add the following code to you php file and you'll understand what's wrong
ini_set('display_errors', 1);
error_reporting(E_ALL);
Upvotes: 1
Reputation: 1175
$sql_string='
UPDATE `TABLE1` SET `row1`= case `id`
when 1 then "'.$val1.'"
when 2 then "'.$val2.'"
when 3 then "'.$val3.'"
end
WHERE `row5 ` in('.$someid.','.$someid.','.$someid.') AND `active`= "yes"';
mysql_query($sql_string);
Upvotes: 1
Reputation: 1175
UPDATE `table` SET `name`= case `id`
when 1 then "Alex"
when 2 then "John"
when 3 then "Steve"
end
WHERE `id` in(1,2,3)
Isn't it?
Upvotes: 1