我有一个多选输入,我需要将选择保存到数据库。1 个选定的student_id = 数据库中的 I 行。我该怎么做?视图:<select select class="js-example-basic-multiple" name="student_id" multiple="multiple" id="student_id" style="width: 100%;"> <option value="">Select student</option></select>控制器:$student_id = $this->input->post(['student_id']);array( "student_id"=>$student_id,感谢您的帮助
1 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
这应该有效
<select name="student_id[]" size="10" multiple="multiple">
$str = '';
foreach ($_POST['student_id'] as $student) {
$str .= $student;
}
$imploded_ids = implode(',', $str);
$student_id = $this->input->post(['student_id']);
array( "student_id"=>$imploded_ids,
编辑:
$iddss = $_POST['student_id'] ; //Take the array of ids.
$values = array() ;
foreach($iddss as $str){
$values[] = $str;
}
$LastValue = implode(",", $values);
$student_id = $this->input->post(['student_id']);
array("student_id"=>$LastValue,
IDD 的使用结果
- 1 回答
- 0 关注
- 71 浏览
添加回答
举报
0/150
提交
取消