Welcome Guest, Not a member yet? Register   Sign In
database insert question
#1

[eluser]TheoR74[/eluser]
Hello, this may be a pretty stuppid question, but here goes....

I have a mysql table with an id field int 11 auto increment.

I want to use the $this->db->insert('table_name') function, but I need to know the number that is put into the id field. Is there any easy way to find that out?

Thanks
Theo
#2

[eluser]Yash[/eluser]
its pretty simple

suppose id name is a_id
Code:
$data = array(
               'a_id' => '' ,
               'name' => 'My Name' ,
               'date' => 'My date'
            );

$this->db->insert('mytable', $data);
#3

[eluser]Developer13[/eluser]
Theo - Here's your answer:

After you insert your data, use $this->db->insert_id() to grab the ID of the record just inserted. For example:

$newly_inserted_id = $this->db->insert_id();

Found in the user guide:

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

[eluser]TheoR74[/eluser]
Thanks Developer13!




Theme © iAndrew 2016 - Forum software by © MyBB