所以,我對於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