Page 1 of 1

SQL Query Using SET and IN Clauses with an Array

Posted: Fri Jun 04, 2010 7:07 pm
by makamo66
I am trying to do an UPDATE with the SET clause:

UPDATE temp_cart SET quantity IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

I know that SET is used only with an equal sign like this:

UPDATE temp_cart SET quantity = 6 WHERE product_id IN ( 2, 4 ) AND user_id = '" . $_SESSION['UID'] . "'

However, I need a way to set the quantity column to more than one value so I want to use the IN clause. I can't just run the query twice because in reality the query is using variables with imploded values and not simply the integers shown here. The query actually looks like this:

$id_nums = implode(", ", $productId2);
$qty_nums = implode(", ", $qtyBox2);
UPDATE temp_cart SET quantity IN ($qty_nums) WHERE product_id IN ($id_nums) AND user_id = '" . $_SESSION['UID'] . "'

I am using MySQL version 5.0. The error message I get is fairly non-descript. It is merely:

Error occured while inserting values into table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN (7, 6) WHERE product_id IN ( 2, 4 ) AND user_id = '20100604164333'' at line 1

Re: SQL Query Using SET and IN Clauses with an Array

Posted: Fri Jun 04, 2010 7:40 pm
by Eran
Please don't double post
viewtopic.php?f=2&t=117195

Re: SQL Query Using SET and IN Clauses with an Array

Posted: Fri Jun 04, 2010 8:13 pm
by Benjamin
:arrow: Locked