Join 2 or more Table in CodeIgniter

CodeIgniter PHP Framework is one that is very popular today, because it provides the framework needs a simple standard data processing. Associated with ease, we also facilitated when we'll do join two or more tables.

In this case I will join explaining the use of join in Active Record provided by CodeIgniter. CodeIgniter join type used is the type of join ON. We assume there are 3 pieces table named paket_pekerjaan, areas and periods. This coding is below.

function selectAll(){
$this->db->select('paket_pekerjaan.Kode_Pkt_Pekerjaan,paket_pekerjaan.Nama_Pkt_Pkrjaan,
paket_pekerjaan.Nilai,bidang.nama_bidang,periode.Nama_Periode')
->join('bidang','bidang.id_bidang=paket_pekerjaan.id_bidang')
->join('periode','periode.id_periode=paket_pekerjaan.ID_Periode');
return $this->db->get('paket_pekerjaan')->result();
}

If we use Active Record, so this query is below

select p.Kode_Pkt_Pekerjaan, p.Nama_Pkt_Pkrjaan, p.Nilai,b.nama_bidang, q.Nama_Periode
FROM paket_pekerjaan p
JOIN bidang b
ON(p.id_bidang = b.id_bidang)
JOIN periode q
ON(p.id_periode = q.id_periode)

That's about join 2 or more tables in CodeIgniter Framework. If what I wrote above coding error or wrong please send comments via the comments box below. Thank you and good luck  :2thumbup

0 Response to Join 2 or more Table in CodeIgniter

Posting Komentar

Silahkan Comment ya untuk kebaikan blog ini...Kritik,saran kami terima dengan senang hati...