3

I want to get data N_KENDALA from table kendala. Table "Kendala" join with Table "Pelayanan"

This is my controller -> pelayanan.php

public function ubah($ID_PELAYANAN){
        $data['Kendala'] = $this->model_pelayanan->kendala();
        $data['Isi'] = $this->model_pelayanan->detail($ID_PELAYANAN);
        $this->load->view('admin/start');
        $this->load->view('admin/header', $data);
        $this->load->view('admin/pelayanan_ubah', $data);
        $this->load->view('admin/footer');
        $this->load->view('admin/script_textarea');
        $this->load->view('admin/end');
    }

This is my model -> model_pelayanan.php

public function detail($ID_PELAYANAN){
    $this->db->select('*');
    $this->db->from('pelayanan');
    $this->db->join('area', 'area.ID_AREA = pelayanan.ID_AREA', 'left');
    $this->db->join('rayon', 'rayon.ID_RAYON = pelayanan.ID_RAYON', 'left');
    $this->db->join('status', 'status.ID_STATUS = pelayanan.ID_STATUS', 'left');
    $this->db->join('kendala', 'kendala.ID_KENDALA = pelayanan.ID_KENDALA', 'left');
    $this->db->join('verifikasi', 'verifikasi.ID_VERIFIKASI = pelayanan.ID_VERIFIKASI', 'left');
    $this->db->order_by('ID_PELAYANAN', 'asc');
    $this->db->where('pelayanan.ID_PELAYANAN', $ID_PELAYANAN);
    $query = $this->db->get();

    if ($query->num_rows()) {
        return $query->result_array();
    } 
    else {
        return false;
    }
}

public function kendala(){
    $this->db->select('*');
    $this->db->from('KENDALA');
    $query = $this->db->get();
    if ($query->num_rows()) {
        return $query->result_array();
    } 
    else {
        return false;
    }
}

And this is my view for comb box -> pelayanan_ubah.php

<div class="form-group">
<label for="KENDALA"> KENDALA </label>                                   <select name="KENDALA" class="form-control">                         
    <?php
        foreach ($KENDALA as $row) {
        echo '<option value="'.$row['ID_KENDALA'].'">'
        .$row['N_KENDALA'].'</option>';
    }
    ?>
    </select>
    </div>

But, when I run, the value of combo box don`t display.

How the solving of this problem?

user5072610
  • 127
  • 2
  • 10

1 Answers1

4

You have an issue in that the data you pass to the view is upper camel case, but the variable you attempt to iterate is capitalized, please observe the following:

public function ubah($ID_PELAYANAN){
    $data['Kendala'] (...) <-- upper camel case

However, in your view, you're using:

foreach ($KENDALA as $row) { <-- capitalized
(...)

Please change $KENDALA to $Kendala

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110