我尝试使用CodeIgniter将数据插入到具有外键的多个表中。
这是我的第一张表koor_pen
no_koor(小学) utm_y | utm_x | latit |隆基
这里是我的第二个表称为input_pen
no_form(主要)| kode_bps | no_obs | no_koor(国外)| t_tanah | catatan使用CodeIgniter框架将数据插入到具有外键的多个表中
这是我的控制器
function c_submit(){
$data = array(
'no_form' => $this->input->post('noform'),
'kode_bps' => $this->input->post('kodebps'),
'no_obs' => $this->input->post('noobs'),
'no_koor' => $this->input->post('nokoor'),
'tanaman_u' => $this->input->post('tutama'),
't_tanah' => $this->input->post('ttanah'),
'catatan' => $this->input->post('cat')
);
$datakoor = array(
'no_koor' => $this->input->post('nokoor'),
'utm_y' => $this->input->post('y'),
'utm_x' => $this->input->post('x'),
'latit' => $this->input->post('deg')." ".
$this->input->post('min')." ".
$this->input->post('sec'),
'longi' => $this->input->post('deg2')." ".
$this->input->post('min2')." ".
$this->input->post('sec2')
);
$no_obs = $this->session->userdata('no_obs');
$this->m_input->m_submit($data, $datakoor);
redirect(base_url("c_input"));
}
和模型
function m_submit($data, $datakoor) {
$this->db->trans_start();
$this->db->insert('koor_pen', $datakoor);
$no_koor = $this->db->insert_id();
$this->db->where('no_koor',$no_koor);
$this->db->insert('input_pen', $data);
$this->db->trans_complete();
return $this->db->insert_id();
}
请检查您在主表中存在的主表中添加的值。 –
如果两张表格在同一时间以一种形式输入会怎样? @PankajSharma – Kiki
@Kiki你会在下面检查我的答案吗? –