Get data from 2 table to display in 1 table using codeigniter and oracle -
i want display table in website, , data 2 table tb_keluhan , tb_unit. here code controller
public function index() { $data['tb_keluhan']=$this->computer_model->get_all_computers(); $this->load->view('header'); $this->load->view('computer_view',$data); $this->load->view('footer'); }
model :
var $table = 'tb_keluhan'; public function get_all_computers() { $this->db->from('tb_keluhan'); $query=$this->db->get(); return $query->result(); }
and view:
<?php foreach($tb_keluhan $computer){?> <tr> <td><?php echo $computer->idkeluhan; ?></td> <td><?php echo $computer->nama; ?></td> <td><?php echo $computer->idunit; ?></td> <td><?php echo $computer->tgl_keluhan; ?></td> <td><?php echo $computer->id_jeniskeluhan; ?></td> <td><?php echo $computer->keluhan; ?></td> <td><?php echo $computer->status; ?></td> <td><?php echo $computer->idpegawai; ?></td> <td><?php echo $computer->tgl_selesai; ?></td> </tr> <?php }?>
with tb_unit
below
( "idunit" number(10,0) not null enable, "unit" varchar2(100 byte), constraint "tb_unit_pk" primary key ("idunit")
and tb_keluhan
:
( "idkeluhan" number(20,0) not null enable, "nama" varchar2(10 byte), "idunit" number(10,0), "tgl_keluhan" date default sysdate, "keluhan" varchar2(200 byte), "status" varchar2(10 byte), "idpegawai" number(10,0), "tgl_selesai" date default sysdate, "id_jeniskeluhan" number(5,0), constraint "tb_keluhan_pk" primary key ("idkeluhan")
i want display table in website using 2 table above idunit
field contain unit
tb_unit
. but, other field tb_keluhan
.
i've read using join, how code? thanks.
to join between table tb_unit
, tb_keluhan
below:
public function get_all_computers() { $query = $this->db->from('tb_unit u') ->join('tb_keluhan k','k.idunit = u.idunit','left') ->get(); if($query) { $result = $query->result(); return $result; } }
you may refer link further information: https://www.codeigniter.com/userguide2/database/active_record.html
hope helps.
Comments
Post a Comment