Skip to content
Advertisement

how to join 4 table or more in codeigniter [closed]

this my model and my function

 function all($npp,$nama_pegawai,$jenis_jabatan,$nama_cabang,$nama_unit,$nama) {
            $this->db->select('*');
            $this->db->from('pegawai');
             $this->db->join('nama_cabang','cabang.kd_cabang=pegawai.kd_cabang');
              $this->db->join                  ('nama_unit','unit_kerja.kd_unit=pegawai.kd_unit');
                              $this->db->join   ('nama','jabatan.kd_jabatan=pegawai.kd_jabatan');
                                 $this->db->join('jenis_jabatan','jenis_jabatan.kd_jenis=jabatan.kd_jenis');



            if($npp!=""){
            $this->db->like('npp',$npp);    
            }    


            if($nama_pegawai!=""){
            $this->db->where('nama_pegawai',$nama_pegawai);
            } 
             if($jenis_jabatan!=""){
            $this->db->where('jenis_jabatan.jenis_jabatan',$jenis_jabatan);
            } 
             if($nama_cabang!=""){
            $this->db->where('cabang.nama_cabang',$nama_cabang);
            } 
             if($nama_unit!=""){
            $this->db->where('unit_kerja.nama_unit',$nama_unit);
            } 
             if($nama!=""){
            $this->db->where('jabatan.nama',$nama);
            }     

            return  $this->db->get();
            }

this my controller

 public function index()
        { 
        if($this->session->userdata('LOGIN')=='TRUE')
     if($this->session->userdata('STATUS')==0){

   $data['judul']='Table Master Cuti namaanan';

        $npp = $this->input->get('npp');
    $nama_pegawai = $this->input->get('nama_pegawai');
     $nama_cabang = $this->input->get('nama_pegawai');
      $nama_unit = $this->input->get('nama_pegawai');
       $nama = $this->input->get('nama');
  $jenis_jabatan = $this->input->get('jenis_jabatan');




        $per_page = abs($this->input->get('per_page'));
        $limit = 10;
        $tot = $this->pegawai_Model->all($npp,$nama_pegawai,$jenis_jabatan,$nama_cabang,$nama_unit,$nama);
        $data['npp']   = $this->pegawai_Model->limit($npp,$nama_pegawai,$jenis_jabatan,$nama_cabang,$nama_unit,$nama, $limit, $per_page);


         $data['nama_pegawai']   = $this->pegawai_Model->nama_pegawai();
          $data['nama_cabang']   = $this->pegawai_Model->nama_cabang();
           $data['nama_unit']   = $this->pegawai_Model->nama_unit();
            $data['nama']   = $this->pegawai_Model->nama();
           $data['jenis_pegawai']   = $this->pegawai_Model->jenis_jabatan();

and this my error

A Database Error Occurred

Error Number: 1146

Table ‘cutionline.nama_cabang’ doesn’t exist

SELECT * FROM (pegawai) JOIN nama_cabang ON cabang.kd_cabang=pegawai.kd_cabang JOIN nama_unit ON unit_kerja.kd_unit=pegawai.kd_unit JOIN nama ON jabatan.kd_jabatan=pegawai.kd_jabatan JOIN jenis_jabatan ON jenis_jabatan.kd_jenis=jabatan.kd_jenis

Filename: C:xampphtdocsjasamargasystemdatabaseDB_driver.php

Line Number: 330

Advertisement

Answer

$this->db->join('table2', 'table2.ID = table1.ID');
$this->db->join('table3', 'table3.ID = table1.ID');
$this->db->join('table4', 'table4.ID = table1.ID', 'left');
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement