2011-09-06 104 views
0

我有兩個表:1.以學生領域是 - (studentid,studentname,批次) 2.分批領域是 - (batchid,batchname)如何填充從數據庫下拉列表中的笨?

我想填充從外地下拉列表「batchname 「(從表中‘批量’),並具有基於現場選擇時將batchName」批量」(從表‘學生’)

我的控制器 -

function update($id){ 
$this->load->model('mod_studentprofile'); 
$data['query']= $this->mod_studentprofile->student_get($id); //to retrieve information from the table "STUDENT" 
$data['query']= $this->mod_studentprofile->batch_get(); 

$data['main_content']='update_studentprofile'; 
$this->load->view('includes/template',$data); 
} 

我的模型 -

function batch_get() 
{ 
    $query = $this->db->get('batch'); 
    return $query->result(); 

}  
現在

,我無法弄清楚如何填充下拉列表中的「查看」。你能否幫我解決這個問題?

在此先感謝。

回答

2

你需要把要顯示在下拉到一個數組的選項,像這樣

$options = array(
    'red' => 'Red', 
    'green' => 'Green', 
    'blue' => 'Blue', 
); 

// The params here are: 
// 'color' => name of the drop down 
// '$options' => options for the drop down 
// 'red'  => the selected value of the drop down 
echo form_dropdown('color', $options, 'red'); 

我會做的就是在我的模型創建功能,說$model->dropdown_options()並用它來獲得來自數據庫的行並將它們放入數組中。

相關問題