1 回答

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊
這是控制器代碼,您將從中獲取數(shù)據(jù)VIEW作為您將在controller.
// Controller
$data_array1 = array(
'table_field_name_here' => $this->input->post('pos_id'),
'table_field_name_here' => $this->input->post('post_usr'),
'table_field_name_here' => $this->input->post('comment'),
);
$data_array2 = array(
'table_field_name_here' => $this->input->post('Project_name'),
'table_field_name_here' => $this->input->post('Proejct_lang'),
);
$table_1 = 'table_name';
$table_2 = 'table_name';
$record_id_1 = $this->Common_model->insert_into_table($table_1, $data_array1);
$record_id_2 = $this->Common_model->insert_into_table($table_2, $data_array2);
if($record_id_1 && $record_id_2){
// success ...!
}else{
// fail ...!
}
model您將從控制器調(diào)用的函數(shù)。
// Model
function insert_into_table($table, $data) {
// echo "<pre>asdf";print_r($data);exit;
$insert = $this->db->insert($table, $data);
$insert_id = $this->db->insert_id();
if ($insert) {
return $insert_id;
} else {
return false;
}
}
希望您能了解使用模型將數(shù)據(jù)插入到兩個(gè)表中是多么簡單。
添加回答
舉報(bào)