php 从多选,多行保存数据

我有一个多选输入,我需要将选择保存到数据库。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,

感谢您的帮助


慕丝7291255
浏览 73回答 1
1回答

人到中年有点甜

这应该有效<select name="student_id[]" size="10" multiple="multiple">$str = '';foreach ($_POST['student_id'] as $student) {&nbsp; &nbsp; $str .= $student;}$imploded_ids = implode(',', $str);$student_id = $this->input->post(['student_id']);&nbsp;array( "student_id"=>$imploded_ids,编辑:$iddss = $_POST['student_id'] ; //Take the array of ids.$values = array() ;foreach($iddss as $str){&nbsp; $values[] = $str;}$LastValue = implode(",", $values);$student_id = $this->input->post(['student_id']);&nbsp; &nbsp; &nbsp; &nbsp;array("student_id"=>$LastValue,IDD 的使用结果
打开App,查看更多内容
随时随地看视频慕课网APP