Kathleen86 Posted December 15, 2020 Share Posted December 15, 2020 Hello everybody, I am trying to update a value in the database but unfortunately, my request isn't taken into account. I checked and the program gets into the function and the conditions but only the update request isn't working. Here is my code, it would be great if you could help me, public function setActiveInactive($active, $id_product) { if($active==1) { Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_attribute a ON p.id_product = a.id_product SET p.active = 0 WHERE a.id_product_attribute = '.(int)$id_product); } else if($active==0) { Tools::dieObject(0); Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_attribute a ON p.id_product = a.id_product SET p.active = 1 WHERE a.id_product_attribute = '.(int)$id_product); } } Thank's a lot ! Kathleen Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 16, 2020 Share Posted December 16, 2020 Bonjour, Merci de parler en français dans la section française du forum ou de poster dans la section correspondant à votre langue. Link to comment Share on other sites More sharing options...
Kathleen86 Posted December 16, 2020 Author Share Posted December 16, 2020 Bonjour, excusez-moi pour l'erreur de langue. Je souhaiterais faire un update avec jointure. Mais ça ne fonctionne pas. Le programme entre bien dans la condition, c'est la requête qui ne s'effectue pas. Pourriez-vous me dire ce qui ne va pas avec ma requête d'update ? Merci d'avance ! public function setActiveInactive($active, $id_product) { if($active==1) { Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_attribute a ON p.id_product = a.id_product SET p.active = 0 WHERE a.id_product_attribute = '.(int)$id_product); } else if($active==0) { Tools::dieObject(0); Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_attribute a ON p.id_product = a.id_product SET p.active = 1 WHERE a.id_product_attribute = '.(int)$id_product); } } Kathleen Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 17, 2020 Share Posted December 17, 2020 https://sql.sh/cours/update Link to comment Share on other sites More sharing options...
Kathleen86 Posted December 17, 2020 Author Share Posted December 17, 2020 Je ne vois pas ce qui est différent de ce qu'il y a dans le cours. Là j'essaie de faire une jointure et c'est pas précisé dans le cours. Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 17, 2020 Share Posted December 17, 2020 https://www.developpez.net/forums/d1045908/bases-donnees/mysql/requetes/requete-update-join/ Link to comment Share on other sites More sharing options...
Kathleen86 Posted December 17, 2020 Author Share Posted December 17, 2020 C'est exactement ce que j'ai fait, ça ne fonctionne pas. 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