Add data to two separate tables |
[eluser]clintonbeattie[/eluser]
Hi, Getting to grips with CI again. I have this model and want to add an image to an images table and reference to a user. Can some please tell me how to do this as the insert is only pointing to one table at the moment, 'membership'? Many thanks, C Code: function create_member()
[eluser]dark_lord[/eluser]
try to get the image filename and save that to the image field in your membership table. http://ellislab.com/codeigniter/user-gui...ading.html
[eluser]clintonbeattie[/eluser]
Cool. Just for future reference, how can I add data to two separate tables?
[eluser]dark_lord[/eluser]
[quote author="modelreject" date="1268861968"]Cool. Just for future reference, how can I add data to two separate tables?[/quote] create two insert query, with both references the same ID (something like the foreign key) For example: Account Table ID (PK, AUTOINCREMENT) USERNAME Image Table IMG_SEQ_ID ID (FK coming from Account table) IMG_FILENAME Address Table ADDRESS_SEQ_ID ID (FK coming from Account Table) ADDRESS_NAME
[eluser]clintonbeattie[/eluser]
Perfect. Thanks. This is what I have now. If there is a better way please let me know. function create_member() { $static_salt = $this->config->item('encryption_key'); $new_member_insert_data = array( 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'email_address' => $this->input->post('email_address'), 'username' => $this->input->post('username'), 'password' => md5($this->input->post('password') . $static_salt) ); $new_member_insert = array( 'first_name' => $this->input->post('first_name'), ); $insert = $this->db->insert('membership', $new_member_insert_data); $insert = $this->db->insert('test', $new_member_insert); return $insert; } |
Welcome Guest, Not a member yet? Register Sign In |