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>
代码视图上面不能显示在数据下拉选择,我想当我点击窗体编辑下拉选择。 哪里是我的错码,如何解决?