0
我有選定的下拉列表的問題,我點擊表單edit.dropdown不能選擇空(選擇)如果數據沒有在數據庫中。 我想,如果數據爲空,下拉像這樣: 所以在這裏我的代碼:編輯窗體選定的值輸入
//mycontroller
public function edit($id) {
$data = array(
'title' => 'Users',
'breadcrumb'=> 'User Edit',
'groups' => $this->groups->get_all(),
'position' => $this->users->get_position(),
'report' => $this->users->get_leader(),
'users' => $this->users->get_by(array('nik' => $id)),
'content' => 'edit'
);
$this->load->view ('default', $data);
}
//my model
public function get_leader()
\t {
\t \t $idstat=array(4);
\t \t $this->db->select('nik');
\t \t $this->db->select('username');
\t \t $this->db->from('t_mtr_employee');
\t \t $this->db->where_in('t_mtr_employee.group_id',$idstat);
\t \t $query= $this->db->get();
\t \t return $query->result();
\t }
<div class="form-group">
<label class="control-label col-md-3">Reporting To<span
class="required"> * </span></label>
<div class="col-md-6">
<select class="form-control" name="reporting">
<option disabled>Choose</option>
<?php
$id = $users->nik;
foreach($report as $report) {
$selected = $id == $report->nik ? 'selected' : '';
echo '<option '.$selected.' value="'.$report->nik.'">'.$report->username.'</option>';
}
?>
</select>
</div>
</div>
代碼視圖上面不能顯示在數據下拉選擇,我想當我點擊窗體編輯下拉選擇。 哪裏是我的錯碼,如何解決?