我想从表kendala获取数据N_KENDALA.表“ Kendala”与表“ Pelayanan”联接
这是我的控制器-> 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');
}
这是我的模型-> 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;
}
}
这是我对梳子盒的看法-> 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>
但是,当我运行时,组合框的值不显示.
如何解决这个问题?
解决方法:
您有一个问题,因为您传递给视图的数据是大写驼峰式的,但是您尝试迭代的变量是大写的,请注意以下几点:
public function ubah($ID_PELAYANAN){
$data['Kendala'] (...) <-- upper camel case
但是,您认为您正在使用:
foreach ($KENDALA as $row) { <-- capitalized
(...)
请将$KENDALA更改为$Kendala