[solved]Getting a Primary Key after inserting into a table? |
[eluser]brucebat[/eluser]
Hello, Im trying to get a PK so I can use it for my Foreign Key in another table. Would it be correct to use the get_where() function for this? Heres my code. Code: //Patient segment Im currently getting this error: Quote:A Database Error Occurred I don't understand how it gets Column '0'? Would it be because it does not specify correctly the column name?
[eluser]brucebat[/eluser]
Thankyou, So how does it know what value to insert? What parameters do I give the function. Could you give me an example?
[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(); 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
[eluser]Mirge[/eluser]
If you had a table like: Code: CREATE TABLE test ( id would be your primary key. Code: $result = $this->db->insert("...."); See: http://ellislab.com/codeigniter/user-gui...lpers.html
[eluser]brucebat[/eluser]
Wow that is too easy to believe. Thanks for the help. |
Welcome Guest, Not a member yet? Register Sign In |