Inserting data into multiple tables |
Hello,
In basic sql command to insert data into multiple table with foreign key relation the last inserted id is helpful. In codeigniter how can I insert data into multiple table with foreign key relation. I'm reading at some helpful tutorials like using transactions. Can someone teach me how to implement in codeigniter or any code snippets that can share in order to help me. I'm still learning this framework. Thanks
with codeigniter you have to create as many array as table you want to insert the data
this will be in your model function addProductCategory($aProductCategory){ $this->db->insert('tbl_products_type',$aProductCategory); } this in in your controller function insertProductCategory(){ $productCategory = array('product_type_name' => $this->input->post('txt_product_category')); $this->mod_Product_Category->addProductCategory($productCategory); } you get the value from the view
(05-31-2017, 08:53 PM)Junie Wrote: Hello, Have you read https://www.codeigniter.com/user_guide/d...tions.html ? (06-01-2017, 12:02 PM)Paradinight Wrote:(05-31-2017, 08:53 PM)Junie Wrote: Hello, I already read this. What Im trying to emphasize is does transaction is the way to insert data from a foreign key constraint? Or theirs other way.
Perhaps it can help you: CodeIgniter Database Helper to Add and Drop Foreign Keys
|
Welcome Guest, Not a member yet? Register Sign In |