2015-05-16 49 views
3

我想問我的程序。 我想編輯但不能在表格中編輯,而在表bahan_baku成功編輯。 請救救我。 我有2個tabel。如何使用codeigniter編輯兩個tabel

表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'); 
} 
} 
+0

你m_update模型你逝去$這個 - > DB->在哪裏( 'id_jurnal',$ id_jurnal);但從你得到這個$ id_jurnal,因爲你只傳遞4個參數$ data_bb,$ id_bahanbaku,$ data_jurnal,$ id_coa,所以我認爲用$ id_coa替換$ id_jurnal,你的問題就解決了。 –

+0

感謝您的評論。但這不起作用。 :(請 –

回答

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

通過$id_coa 更換$id_jurnal請參閱參數名: -

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

感謝評論。但這不起作用。:( –

+0

檢查你的模型它說類M_bahanbaku擴展CI_Controller,但它必須說M_bahanbaku類擴展CI_Model,這就是你如何在codeigniter中創建模型 –

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); 
    } 
} 

檢查我的代碼,並與您比較,我希望這會解決您的問題。

問候

+0

感謝您的評論。不起作用。:( –