я пытаюсь вызвать поле tb_pemeliharaan.isi_kriteria max_value
и min_value
с соединением tb_pemeliharaan.id_kriteria tb_kriteria.id_kriteria
это мой контроллер:
function Index()
{
$data['data'] = $this->PenilaianModel->GetPerKendaraan();
if($this->session->userdata['logged_in']['level']=="1"){
$id_merk = $this->uri->segment(3);
$data['data'] = $this->PenilaianModel->GetPerKendaraan();
$data['kriteria'] = $this->PenilaianModel->GetKriteria();
$data['getsifat'] = $this->PenilaianModel->getDataSifat(); //call model
$this->template->load('template', 'Data/DataPenilaian', $data);
}else{
$data['error'] = 'Anda tidak dapat mengakses halaman tersebut.';
$this->template->load('template', 'error', $data);
}
}
это моя модель:
public function getDataSifat()
{
$this->db->select('DISTINCT(tb_pemeliharaan.id_kendaraan), nama, platno');
$this->db->from('tb_pemeliharaan');
$this->db->join('tb_kendaraan', 'tb_kendaraan.id_kendaraan = tb_pemeliharaan.id_kendaraan');
$query = $this->db->get();
$data = array();
$index = 0;
if($query->num_rows() > 0)
{
foreach($query->result() as $kr_key => $x){
$data[$kr_key] = array(
'id_kendaraan' => $x->id_kendaraan,
'nama' => $x->nama,
'platno' => $x->platno,
);
$id_kendaraann = $this->db->where('id_kendaraan', $x->id_kendaraan);
$this->db->select('*');
$this->db->from('tb_pemeliharaan');
$query = $this->db->get();
$id_kendaraann = $query->result();
foreach($id_kendaraann as $z){
$data[$kr_key]['sub'][] = array(
'id_kendaraan' => $z->id_kendaraan,
'id_kriteria' => $z->id_kriteria,
'isi_kriteria' => $z->isi_kriteria // key
);
$this->db->select_max('tb_pemeliharaan.isi_kriteria', 'max_value'); //my error
$this->db->select_min('tb_pemeliharaan.isi_kriteria', 'min_value'); // my error
$this->db->select('tb_kriteria.id_kriteria, nama_kriteria, sifat, bobot');
$this->db->from('tb_pemeliharaan');
$this->db->where('tb_pemeliharaan.id_kriteria',$z->id_kriteria); // i call for key
$this->db->join('tb_kriteria', 'tb_kriteria.id_kriteria = tb_pemeliharaan.id_kriteria');
$query = $this->db->get();
$kriteria = $query->result();
foreach($kriteria as $k){
// 0 cost, 1 benefit
if($k->sifat == "1" ){
$hasil = $k->max_value; // max value not same with database
}
else if ($k->sifat == "0" ) {
$hasil = $k->min_value; // min value not same with database
}
$data[$kr_key]['sub']['dari'][] = array(
'isi' => $hasil
);
}
}
$index++;
}
return $data;
// var_dump($data);
} else{
return NULL;
}
}
в моей модели max_value
и min_value
должны быть получены данные isi_kriteria
из tb_pemeliharaan
where tb_pemeliharaan.id_kriteria == $z->id_kriteria
пример: в моем критерии tb_kriteria значение моего поля равно item_broken
в базе данных равно 2 , 5,8 но если я попробую эту модель max_value
результат будет 5 .... почему? должен быть ответ 8 верно?
мой взгляд:
<!-- Basic datatable -->
<div class="panel panel-flat">
<div class="panel-heading">
<h5 class="panel-title">Conversi berdasarkan sifat</h5>
<div class="heading-elements">
<ul class="icons-list">
<li><a data-action="collapse"></a></li>
<li><a data-action="reload"></a></li>
<li><a data-action="close"></a></li>
</ul>
</div>
</div>
<table class="table datatable-basic">
<thead>
<tr>
<th>No</th>
<th>Kendaraan</th>
<th>Plat Nomor</th>
<?php
$no=1;
if(!empty($kriteria)) {
foreach ($kriteria as $isi) { ?>
<th><?php echo $isi['nama_kriteria'] ?></th>
<?php }} ?>
</tr>
</thead>
<tbody>
<?php
$no=1;
if(!empty($getsifat)) {
foreach ($getsifat as $kr_key => $kendaraan) { ?>
<tr>
<td><?php echo $no ?> </td>
<td><?php echo $kendaraan['nama'] ?> </td>
<td><?php echo $kendaraan['platno'] ?></td>
<?php foreach ($kendaraan['sub']['dari'] as $data) { ?> // i call isi from model
<td><?php echo $data['isi'] ?></td>
<?php } ?>
</tr>
<?php $no++; }} ?>
</tbody>
</table>
</div>
<!-- /basic datatable -->
спасибо за ваш ответ ...