
Originally Posted by
mc12345678
Perhaps unnecessary for you, but others that land on this page, the php version of the statement would be:
PHP Code:
<?php
$cat_holding = 15; // category that contains products to stay in category.
$db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id in (select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id=" . $cat_holding .") and categories_id != ". $cat_holding);
That method will include any table prefix associated with the database and not require consideration/addition of it.
I tried that in a stand alone php file and it didn't work????
PHP Code:
<?php
require('includes/application_top.php');
global $db;
$cat_holding = 15; // category that contains products to stay in category.
$db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id in (select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id=" . $cat_holding .") and categories_id != ". $cat_holding);
Using zen 1.5.1
mysql 5.1.68-rel14.6-log
php 5.4.12
table prefix zen_
I get the same error as when I used the SQL version without an alias
Code:
[16-Nov-2014 17:47:44 Australia/Melbourne] PHP Fatal error: 1093:You can't specify target table 'zen_products_to_categories' for update in FROM clause :: delete from zen_products_to_categories where products_id in (select products_id from zen_products_to_categories where categories_id=15) and categories_id != 15 in /home/******/public_html/zen151/includes/classes/db/mysql/query_factory.php on line 120
(The table prefix isn't an issue)
What versions are you using?