![]() |
How do I return the insert_id value from a database model to use in a query? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How do I return the insert_id value from a database model to use in a query? (/showthread.php?tid=50352) |
How do I return the insert_id value from a database model to use in a query? - El Forum - 03-23-2012 [eluser]dallen33[/eluser] Well, I do know how to return it, but I'm clearly doing something wrong. So in my database model: Code: $this->db->insert('online_booking', $form_data); Code: if ($this->form_model->online_booking($this->input->post())): Code: $this->data['order'] = $this->db->get_where('online_booking', array('id' => $this->form_model->online_booking($this->input->post())))->row(); What's the proper way to do this? How do I return the insert_id value from a database model to use in a query? - El Forum - 03-23-2012 [eluser]dallen33[/eluser] I wish I could delete this! Did this instead: Code: $form_db = $this->form_model->online_booking($this->input->post()); How do I return the insert_id value from a database model to use in a query? - El Forum - 03-23-2012 [eluser]InsiteFX[/eluser] Code: $id = $this->db->insert_id(); How do I return the insert_id value from a database model to use in a query? - El Forum - 03-23-2012 [eluser]dallen33[/eluser] [quote author="InsiteFX" date="1332526108"] Code: $id = $this->db->insert_id(); Would that still work in the controller after the db stuff is being done in a model? How do I return the insert_id value from a database model to use in a query? - El Forum - 03-24-2012 [eluser]xtremer360[/eluser] No what you would need to do is after you run your query in your model then assign an id variable to the insert id as per the code above and then return it from your model function. So you'd end up with: Code: function queryFunction() |