sooraj s pillai
sooraj s pillai

Reputation: 916

how to save id of one table to another table in codeigniter?

i want to save id of one table to another table how should i write the model and controller.

For example : I have a database like this

tbl1: (id,content,time,date,category)

tbl2: (id,tbl1_id,category_detail)

Upvotes: 0

Views: 945

Answers (1)

Naveed Ramzan
Naveed Ramzan

Reputation: 3593

$tbl1Data = array(
    'id'            => '',
    'content'   =>  'Hi, content will be here',
    'time'   =>  date("H:i:s"),
    'date' => date("Y-m-d"),
    'category'        =>  'Electronics'
);
$this->db->insert('tbl1',$postData);
$recordId $this->db->insert_id();

$tbl2Data = array(
    'id' => '',
    'tbl1_id' => $recordId,
    'category_detail' => "alskjdflkajsdlk falsjdflka lsdkfj as",
);
$this->db->insert('tbl1',$postData);

Upvotes: 1

Related Questions