我有一個多選輸入,我需要將選擇保存到數據庫。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 關注
- 92 瀏覽
添加回答
舉報
0/150
提交
取消