Welcome Guest, Not a member yet? Register   Sign In
Inserting data into multiple tables
#1

(This post was last modified: 05-31-2017, 08:53 PM by Junie.)

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 Smile
Reply
#2

(This post was last modified: 06-01-2017, 11:20 AM by shaser.)

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
Reply
#3

(05-31-2017, 08:53 PM)Junie Wrote: 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 Smile

Have you read https://www.codeigniter.com/user_guide/d...tions.html ?
Reply
#4

(06-01-2017, 12:02 PM)Paradinight Wrote:
(05-31-2017, 08:53 PM)Junie Wrote: 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 Smile

Have you read https://www.codeigniter.com/user_guide/d...tions.html ?

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.
Reply
#5

Perhaps it can help you: CodeIgniter Database Helper to Add and Drop Foreign Keys
Reply




Theme © iAndrew 2016 - Forum software by © MyBB