Get data from table with combo box (Codeigniter)

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

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 of the comb -> 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 combo box value is not displayed.

How to solve this problem?

+3


source to share


1 answer


You have a problem that the data you are passing to the view is of camel camel, but the variable you are trying to iterate over is capitalized, note the following:

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

      

However, in your opinion, you are using:



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

      

Change $KENDALA

to$KENDALA

+4


source







All Articles