Welcome Guest, Not a member yet? Register   Sign In
[solved]Getting a Primary Key after inserting into a table?
#4

[eluser]defectivereject[/eluser]
not sure where you're trying to get the primary key in your code
BUT AFTER
Code:
$insertpatient = $this->db->insert ('patient', $patient);

putting $this->db->insert_id();
returns the ID of the row it just inserted.
so instead of putting

Code:
$this->db->insert_id();
you could put
Code:
$p_id = $this->db->insert_id();

then $p_id is set as the ID of the last insert ID in the patient table. and can be used as the value for your next table
Code:
$patient2 = array
            (
                'patient' =>$p_id,
                'patient_whatNowr' => $this->input->post ('patient_whatNow')
            );
        
            $insertpatient = $this->db->insert ('patient2', $patient2);


Messages In This Thread
[solved]Getting a Primary Key after inserting into a table? - by El Forum - 07-05-2011, 09:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB