Welcome Guest, Not a member yet? Register   Sign In
How do I Return the id of last entry added to database?
#1

[eluser]Zac G.[/eluser]
Hi,

I am running the following command:

Code:
$this->db->set('course_id', $course_id);
$this->db->set('name', $name);
$this->db->set('term', $term);
$this->db->insert('courses');

and I want to return the id (auto incremented) of the entry just added.

Any suggestions on how to go about this?

Cheers,
Zac
#2

[eluser]Chad Fulton[/eluser]
Can't go wrong using the manual, I suppose.

http://ellislab.com/codeigniter/user-gui...lpers.html
#3

[eluser]JamieBarton[/eluser]
Simply use

Code:
$this->db->insert_id()

Assign this to an array for easier usage.
#4

[eluser]Zac G.[/eluser]
How is it I read that page 100 times and skipped the first helper every time through?!?

Thanks for a fresh pair of eyes :p




Theme © iAndrew 2016 - Forum software by © MyBB