How To Delete Multiple Items Of Multiple Tables Using PHP and MySQL
| From: | @ Nilaab | Date: | Tue, 31 Dec 2002 18:36:34 +0000 |
| Subject: | How To Delete Multiple Items Of Multiple Tables Using PHP and MySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-129785@lists.php.net to get a copy of this message | ||
Hello Everyone,
I want to DELETE multiple items of multiple TABLES in a MySQL database. My
version of MySQL is 3.23, which means this version doesn't support the
DELETE functionality on multiple tables. The following is my PHP code, where
$item_id is a multi-dimensional array containing the ids of the items I want
to delete from the table.
# DELETE records
for ($i = 0; $i < count($item_id); $i++) {
$query_item2 .= "DELETE QUICK FROM item_dimension WHERE item_id =
'".$item_id[$i][0]."'; ";
$query_item2 .= "DELETE QUICK FROM item_popup WHERE item_id =
'".$item_id[$i][0]."'; ";
}
When I run this through the database using PHP, it returns a syntax error in
the SQL. So what I did was echo out $query_item2, then copied and pasted the
SQL into the MySQL application manually, and ran it through. Well the exact
same SQL statement that I used in PHP worked when I entered it manually in
MySQL. In other words it didn't work doing it through PHP, but it worked in
MySQL directly. What gives? Is there a better way to delete multiple items
from multiple tables with one SQL string? I don't want to separate the two
DELETE functions and run them through two separate times because of overhead
concerns. I tried looking on the MySQL and PHP website for better ways of
using DELETE syntax on multiple tables, but I had no luck finding anything
useful with my version of MySQL. Any help would be greatly appreciated.