RE: [PHP-DB] MYSQL IN A PHP LOOP
| From: | Bastien Koert | Date: | Wed, 09 Nov 2005 18:57:31 +0000 |
| Subject: | RE: [PHP-DB] MYSQL IN A PHP LOOP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-40634@lists.php.net to get a copy of this message | ||
You can't stack queries this way. PHPMyAdmin parses out the queries based on the ';'. You will need to run the query after each one is created.
Bastien
From: "Malcolm JC Clark" <malcolm@gometal.co.uk> Reply-To: <malcolm@gometal.co.uk> To: <php-db@lists.php.net> Subject: [PHP-DB] MYSQL IN A PHP LOOP Date: Wed, 9 Nov 2005 18:12:11 -0000 I have a php function that creates the following SQL below with this statement in the loop: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $myQuery .= " UPDATE page SET page_order_id = \"$page_order_id\" WHERE page_id = \"$page_id\"; "; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $myQuery looks finally like this: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UPDATE page SET page_order_id = "3" WHERE page_id = "1"; UPDATE page SET page_order_id = "5" WHERE page_id = "2"; UPDATE page SET page_order_id = "2" WHERE page_id = "3"; UPDATE page SET page_order_id = "5" WHERE page_id = "4"; UPDATE page SET page_order_id = "6" WHERE page_id = "5"; UPDATE page SET page_order_id = "2" WHERE page_id = "13"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I get this (custom)error when the query is sent to mysql_query() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Err: You have an error in your SQL syntax near '; UPDATE page SET page_order_id = "5" WHERE page_id = "2"' at line 4 Err No.:1064 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Stuck into PhpMyAdmin does not produce an error, and I know that there are functions behind PhpMyAdmin that format user's SQL statements, and I wish I knew how!! It is maybe something to do with the semi-colons? Or that I can not normally send several UPDATE statements in one query??? PLease help. Malc___ __ _ _ ____ ___/ __) /__\ ( \/\/ )( _ \ / __)\__ \ /(__)\ ) ( )(_) )\__ \(___/(__)(__)(__/\__)(____/ (___/ Strategically Applied Web Development Systems Contact: Malcolm JC ClarkTel: 0161 408 2883Mobile: 07779 034 868 This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php