db_join adds new record to left table |
here is my model function
Code: class Tincture_model extends CI_Model {
What do you mean by "it duplicates"? And what is the last record? can we se the query result?
Website: http://avenir.ro
Thank you!
This is the result of last_query(): (captured right before the return in the model function) Code: SELECT `tincture`.*, `ps_product_lang`.`name` as `ps_name`, `tincture`.`name` as `tincture_name` FROM `tincture` LEFT JOIN `ps_product_lang` ON `tincture`.`ps_product_id` = `ps_product_lang`.`id_product` GROUP BY `tincture`.`tincture_id` This is the result of print_r($query->result()): (already inserted one record) Code: Array ( [0] => stdClass Object ( [tincture_id] => 1 [ps_product_id] => 13 [name] => Sibirian Ginseng [is_product] => 1 [ps_name] => Siberian Ginseng [Eleutherococcus senticosus] [tincture_name] => Sibirian Ginseng ) [1] => stdClass Object ( [tincture_id] => 2 [ps_product_id] => 10 [name] => Pau d'Arco [is_product] => 1 [ps_name] => Pau d'Arco [Tabebuia impetiginosa] [tincture_name] => Pau d'Arco ) [2] => stdClass Object ( [tincture_id] => 3 [ps_product_id] => 1 [name] => Cat's Claw [is_product] => 1 [ps_name] => Cat's Claw uña de gato [Uncaria tomentosa] [tincture_name] => Cat's Claw ) [3] => stdClass Object ( [tincture_id] => 44 [ps_product_id] => 1 [name] => Cat's Claw [is_product] => 1 [ps_name] => Cat's Claw uña de gato [Uncaria tomentosa] [tincture_name] => Cat's Claw ) [4] => stdClass Object ( [tincture_id] => 45 [ps_product_id] => 1 [name] => Cat's Claw [is_product] => 1 [ps_name] => Cat's Claw uña de gato [Uncaria tomentosa] [tincture_name] => Cat's Claw ) ) here is the controller: Code: function index()
I am sorry but I still don't see the duplicated record... There are 4 records, all with different ids.
Website: http://avenir.ro
I would guess that your first query in the IF() is failing, which makes it go to the ELSE, which is:
Code: $this->tincture_create(); Your first query is a select, not an insert or update, so it's impossible for that to be adding anything whatsoever to the database.
(01-22-2015, 01:51 PM)Avenirer Wrote: I am sorry but I still don't see the duplicated record... There are 4 records, all with different ids. I was not clear. Somehow the last record gets copied into a new record. Since it is autoincrement, a new id gets created. With every run a new record gets created.
(01-22-2015, 05:06 PM)CroNiX Wrote: I would guess that your first query in the IF() is failing, which makes it go to the ELSE, which is: I took the if else off and against my prediction it worked especially because Code: $this->tincture_create(); So thank you all - it works - even have no explanation. |
Welcome Guest, Not a member yet? Register Sign In |