Primary Key question |
[eluser]codelearn[/eluser]
Hi guys, Is there a way to use the "insert" function of active record, and then retrieve the "id" column immediately following creation. Example: $this->db->set('tagline',$this->input->post('tagline')); $this->db->insert('group_group'); Now I want the ID of the row I just created... without using the tagline/where statement. Thanks!
[eluser]davidbehler[/eluser]
http://ellislab.com/codeigniter/user-gui...lpers.html The function your are looking for is this: Code: $this->db->insert_id()
[eluser]codelearn[/eluser]
So would I do: $this->db->insert_id(‘group_group’); Thanks
[eluser]pistolPete[/eluser]
No, just Code: $this->db->insert_id()
[eluser]davidbehler[/eluser]
No need for the parameter. Just to do this immediatly after your insert: Code: $primary_key = $this->db->insert_id(); That's it. Of course you can call your variable whatever you want. |
Welcome Guest, Not a member yet? Register Sign In |