我想從數據庫中填充下拉列表。在我看來,我的文件有下面的代碼如何獲取form_dropdown()在Codeigniter中顯示選定的值?
$batch= $query ['batch']; // I pull this data from a separate model
echo form_dropdown('shirts', $options, $batch);
現在下拉列表填充數據很好,但問題是我不明白的價值 - 「$一批」自動選擇頁面加載時。有趣的是,如果我回聲$批處理,在頁面的其他地方它顯示正確的數據,這意味着$批處理是好的。
這裏是我的控制器
function update($id){
$this->load->model('mod_studentprofile');
$data['query']= $this->mod_studentprofile->student_get($id);
$data['options']= $this->mod_studentprofile->batchget();
$data['tab'] = "Update Student Information";
$data['main_content']='update_studentprofile';
$this->load->view('includes/template',$data);
}
這裏是我的模型
function batchget() {
$this->db->select('batchname');
$records=$this->db->get('batch');
$data=array();
foreach ($records->result() as $row)
{
$data[$row->batchname] = $row->batchname;
}
return ($data);
}
你請請幫我解決這個問題。我希望在頁面加載時在下拉列表中自動選擇值「$批量」。
在此先感謝。
編輯...我對student_get模型($ ID)
function student_get($id)
{
$query=$this->db->get_where('student',array('studentid'=>$id));
return $query->row_array();
}
謝謝:)
@ Chris Schmitz。謝謝你的回覆。在選擇視圖中呈現的HTML is- $ batch = $ query ['batch']; echo form_dropdown('shirts',$ options,$ batch); –