如何使用codeigniter编辑两个tabel

时间:2015-05-16 03:19:34

标签: codeigniter codeigniter-2

我想问问我的节目。 我想编辑但不能在表bahan_baku成功编辑的表jurnal中编辑。 请救救我 我有2个表格。

表bahan_baku id_bahanbaku keterangan_bb tanggal_bb jumlah_bb harga_bb

表jurnal id_jurnal id_coa tanggal debet kredit

这是我的模特 - > m_bahanbaku.php

function m_edit($data_bb){
    $this->db->where($data_bb);
    $edit_bb = $this->db->get('bahan_baku');
return $edit_bb->result();

    $this->db->where($data_jurnal);
    $edit_jurnal = $this->db->get('jurnal');

return $edit_jurnal->result();
}
function m_update($data_bb, $id_bahanbaku,$data_jurnal, $id_coa){
    $this->db->where('id_bahanbaku', $id_bahanbaku); //untuk tabel bahan_baku
    $this->db->update('bahan_baku', $data_bb);
    $this->db->where('id_jurnal', $id_jurnal); //dari tabel jurnal
    $this->db->update('jurnal', $data_jurnal);

} }

这是我的控制器 - > bahanbaku.php

 function edit($id_bahanbaku){
    $data_bb=array(
        'id_bahanbaku'=>$id_bahanbaku
        );
    $data_jurnal=array(
        'id_jurnal'=>$id_bahanbaku
        );  
    $data_bb['data_edit']=$this->m_bahanbaku->m_edit($data_bb, $data_jurnal);
    $this->load->view('keuangan/v_edit_bb',$data_bb, $data_jurnal);
 }
 function update(){
    $id_bahanbaku = $this->input->post('id_bahanbaku');
        $data_bb=array(
        'keterangan_bb' => $this->input->post('keterangan_bb'),
        'tanggal_bb' => $this->input->post('tanggal_bb'),
        'jumlah_bb' => $this->input->post('jumlah_bb'),
        'harga_bb' => $this->input->post('harga_bb')

        );
    $id_jurnal = $this->input->post('id_jurnal');
         $data_jurnal=array(
         'tanggal' => $this->input->post('tanggal_bb'),
         'debet'=>$this->input->post('harga_bb'),
         'kredit'=>$this->input->post('harga_bb')
         );
        $this->m_bahanbaku->m_update($data_bb, $id_bahanbaku, $data_jurnal, $id_jurnal);
        redirect(base_url().'keuangan/bahanbaku/lihat');
 }
}

2 个答案:

答案 0 :(得分:0)

> $this->db->where('id_jurnal', $id_jurnal);

$id_jurnal替换为$id_coa 请参阅参数名称: -

function m_update($data_bb, $id_bahanbaku,$data_jurnal, `$id_coa`)

答案 1 :(得分:0)

function m_update($data_bb, $id_bahanbaku,$data_jurnal, $id_coa){
    $this->db->where('id_bahanbaku', $id_bahanbaku); //untuk tabel bahan_baku
    $this->db->update('bahan_baku', $data_bb);

    $this->db->where('id_jurnal', $id_coa); //dari tabel jurnal
    $this->db->update('jurnal', $data_jurnal);
   }
} 

检查我的代码并与您进行比较,我希望这可以解决您的问题。

此致