所以,我对于Opencart的导入/导出模块,但它抹在整个产品选项表中插入新的数据之前...如何从表中删除所有内容,除了MySQL中的1项外?
我需要开发第三方产品选择模块我有支持,但在同时 - 我想我会阻止它删除我的产品选项表中的重要列。
在product_option_value
表中,我有'product_option','product_id','quantity'等,并且有一列名为'info',我不想擦除。方法如下:
function storeOptionsIntoDatabase(&$database, &$options)
{
// find the default language id
$languageId = $this->getDefaultLanguageId($database);
// start transaction, remove options
$sql = "START TRANSACTION;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option`;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_description` WHERE language_id=$languageId;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value`;\n";
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value_description` WHERE language_id=$languageId;\n";
$this->import($database, $sql);
...more code...
}
我不是那熟悉的MySQL,但我想要的东西效果的:
$sql .= "DELETE FROM `".DB_PREFIX."product_option_value` WHERE column != 'info';\n";
谢谢!
编辑:
我想迈克尔的使用UPDATE
并明确建议他们都设置为NULL ......但返回此错误:
Error: Duplicate entry '0' for key 1 Error No: 1062 UPDATE
oc_product_option_value
SET product_option_value_id=NULL, product_option_id=NULL, product_id=NULL, quantity=NULL, subtract=NULL, price=NULL, prefix=NULL, sort_order=NULL, weight=NULL, sku=NULL, image=NULL
我试图取出主键:
$sql .= "UPDATE
".DB_PREFIX."product_option_value
SET product_option_id=NULL, product_id=NULL, quantity=NULL, subtract=NULL, price=NULL, prefix=NULL, sort_order=NULL, weight=NULL;\n";
,但我得到:
Error: Duplicate entry '1' for key 1 Error No: 1062 INSERT INTO `oc_product....
编辑:
好了,所以我删除了从插入了“primary_key”字段...和我从上传任何错误消息。但是,当我看到一个产品,产品的选择,我得到这个消息,我的网页的顶部:
Notice: Undefined index: name in /httpdocs/ocart/catalog/model/catalog/product.php on line 418Notice: Undefined index: name in /httpdocs/ocart/catalog/model/catalog/product.php on line 418Notic.... it repeats
查询有什么问题。似乎对我很好。 – Nishant 2011-03-31 13:53:32
最后的陈述是正确的。 – Emmerman 2011-03-31 13:56:34
好吧,就这样做....你可能需要'<>'而不是'!='。在手册中查找MySQL操作符语法。 – 2011-03-31 14:03:21