我需要添加诸如"良好"、"非常好"one_answers"正在改善"等备注。到数据库的rem1
列。在下拉列表中选择的注释应保存在表中。然而,当我执行下面的代码时,我得到一个空值。我做错了什么?
<div>
<select class="form-control" name="remark">
<option value="" disabled selected>Choose option</option>
<option name="exam_group_student_remark_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="Good">Good</option>
<option name="exam_group_student_remark_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="Very Good">Very Good</option>
<option name="exam_group_student_remark_<?php echo $student['exam_group_class_batch_exam_students_id']; ?>" value="Improving">Improving</option>
</select>
</div>
控制器:
if (!empty($exam_group_student_id)) {
foreach ($exam_group_student_id as $exam_group_student_key => $exam_group_student_value) {
$array = array(
'exam_group_class_batch_exam_subject_id' => $this->input->post('exam_group_class_batch_exam_subject_id'),
'exam_group_class_batch_exam_student_id' => $exam_group_student_value,
'rem1' => $this->input->post('exam_group_student_remark_' . $exam_group_student_value),
);
$insert_array[] = $array;
}
}
$this->examgroupstudent_model->add_result($insert_array);
使用这样的代码,在php中取name属性在'select'标签中而不是在'option'标签中
<div>
<select class="form-control" name="remark">
<option value="" disabled selected>Choose option</option>
<option value="Good">Good</option>
<option value="Very Good">Very Good</option>
<option value="Improving">Improving</option>
</select>
</div>
//controller
if (!empty($exam_group_student_id)) {
foreach ($exam_group_student_id as $exam_group_student_key => $exam_group_student_value) {
$array = array(
'exam_group_class_batch_exam_subject_id' => $this->input->post('exam_group_class_batch_exam_subject_id'),
'exam_group_class_batch_exam_student_id' => $exam_group_student_value,
'rem1' => $this->input->post('remark'),
);
$insert_array[] = $array;
}
}
$this->examgroupstudent_model->add_result($insert_array);