banditbirds Posted June 5, 2016 Share Posted June 5, 2016 Hi all, Hopefully someone can point out what I'm doing wrong? I'm trying to delete every product from an array. But this doesn't seem to work. When I use an SQL Delete statement it works correctly: $proddeleted = Db::getInstance()->Execute(' DELETE FROM `'.pSQL(_DB_PREFIX_).'product` WHERE reference = "'.($prodref).'" '); But this only deletes the product record, not the prod_lang etc... So I'm trying to user $product->delete() $prodref = 'CUST'.$quoteid; $products = Db::getInstance()->ExecuteS(' SELECT * FROM `'.pSQL(_DB_PREFIX_).'product` WHERE reference = "'.($prodref).'" '); foreach ($products as $id_product) { $product = new Product((int)$id_product); $product->delete(); } Thanks all!! 1 Link to comment Share on other sites More sharing options...
rocky Posted June 6, 2016 Share Posted June 6, 2016 Seems you're getting all columns from the table and you've forgotten that the result will have the column names as the indexes of the array. Try the following instead: $prodref = 'CUST'.$quoteid; $products = Db::getInstance()->ExecuteS(' SELECT `id_product` FROM `'.pSQL(_DB_PREFIX_).'product` WHERE reference = "'.($prodref).'" '); if (is_array($products) && count($products) > 0) { foreach ($products as $product_array) { $product = new Product((int)$product_array['id_product']); $product->delete(); } } I haven't tested this code, so you'll have to test it yourself. 1 Link to comment Share on other sites More sharing options...
banditbirds Posted June 6, 2016 Author Share Posted June 6, 2016 @rocky perfect!! thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now