如何将详细数据从一个表单插入到数据库postgresql中的两个表中,并在控制器中使用foreach?

时间:2016-11-01 06:47:27

标签: postgresql codeigniter-3

我的控制器中的代码不起作用,并给我这样的警告: 无效参数foreach

public function create_action() 
{
    $this->_rules();

    if ($this->form_validation->run() == FALSE) {
        $this->create();
    } else {
        $usulan = array(
            'unit_id' => $this->input->post('unit_id',TRUE),
            'layanan_id' =>$this->input->post('layanan_id', TRUE),
            'surat_unit_no' => $this->input->post('surat_unit_no',TRUE),
            'usulan_tgl' =>$this->input->post('usulan_tgl', TRUE),
        );

        $id = $this->m_usulan->insert($usulan);

        $this->db->from('usulan_detail');
        $this->db->where('usulan_detail.id', $id);
        $this->db->join('usulan', 'usulan.usulan_id = usulan_detail.usulan_id', 'left');
        $usulan_detail = $this->input->post('usulan_detail');
        //prepare the data into a multidimensional array
        $data = array();
        foreach($usulan_detail as $row)
        {
          // if this is the first clip of a new sheet, make a new entry for it
          if (!isset($data[$row['usulan_id']]))
          {
            $data[$row['usulan_id']] = $row;
            $data[$row['usulan_id']]['usulan_detail'] = array(
                'usulan_id' => $id,
                'pegawai_nip' => $this->input->post('pegawai_nip[]',TRUE),
                'usulan_id' =>  $this->input->get('usulan_id[]',TRUE),
                'gol_lama_id' =>$this->input->post('gol_lama_id[]', TRUE),
                'gol_baru_id' =>$this->input->post('gol_baru_id[]', TRUE)
                );
          }  
          $data[$row['usulan_id']]['usulan_detail'][] = $row;
        }
    }
}

0 个答案:

没有答案