我无法将我在学年一学期设定的价值从数据库下载到下拉列表。
以下是edit_class_view.php的代码:
<div class="form-group">
<label class="control-label col-lg-2"> School Year-Semester:</label>
<div class="col-lg-4">
<?php
echo form_open('main/editClass');
$options = array(
'' => 'Select School Year and Semester',
'SY 2016-2017 2nd Sem' => 'SY 2016-2017 2nd Sem',
'SY 2017 Summer' => 'SY 2017 Summer',
'SY 2017-2018 1st Sem' => 'SY 2017-2018 1st Sem',
);
echo "<div class='drop_pos'>";
echo form_dropdown('schoolyearsemester', $options, 'class="btn dropdown-toggle"', 'required="required"', 'data-toggle="dropdown-menu"', 'value="<?php echo $row->School_Year_Semester;?>"');
?>
<div class="text-danger"><?php echo form_error('schoolyearsemester'); ?></div>
</div>
</div>
</div>
答案 0 :(得分:0)
如果它真的是codeigniter而不是你必须从模型中获取这些年份将它们存储在控制器中的关联数组中,然后将其发送到您的视图。喜欢
public function form()
{
$data['years']=$this->school_model->getSemesterYears();
// Call your view
$this->load->view('myFormViewame',$data);
}
在模型中创建类似
的功能 public function getSemesterYears()
{
// Create Query as per your conditions
$st=$this->db->select('*')->from('tableName')->get()->result_array();
return $st;
}
答案 1 :(得分:0)
form_dropdown('schoolyearsemester', $options, 'class="btn dropdown-toggle"', 'required="required"', 'data-toggle="dropdown-menu"', 'value="<?php echo $row->School_Year_Semester;?>"');
使用此代替上述内容。
form_dropdown('schoolyearsemester', $options, $row->School_Year_Semester, 'class="btn dropdown-toggle"', 'required="required"', 'data-toggle="dropdown-menu"');