2011-09-06 147 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()并用它来获得来自数据库的行并将它们放入数组中。

相关问题