sooraj s pillai sooraj s pillai - 10 days ago 6
SQL Question

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)

Answer
$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);