我使用jquery multiselect来显示我的数据
这就是我在观看中显示数据的方式
<td><select class="multiselect" multiple="multiple" name="id_c[]">
<?php foreach ($test as $data): ?>
<option value="<?php echo $data->id_a ?>" ><?php echo $data->nama ?></option>
<?php endforeach; ?>
</select><td>
这就是我如何在我的模型中保存到数据库中
function save(){
$id_c= $this->input->post('id_c');
var_dump($id_c);
$idb = '';
$count = count($id_c);
$i=0;
foreach($id_c as $e){
if($i < $count -1){
$idb .= $e.', ';
}else{
$idb .= $e;
}
$i++;
}
$tanggal = $this->input->post('tanggal');
$data=array(
'id_c'=>$idb,
'tanggal'=>$tanggal
);
$this->db->insert('detail',$data);
}
但是当我点击提交时,该值没有进入数据库
我尝试使用var_dump,这就是我得到的 布尔(假)
消息:为foreach()提供的参数无效
答案 0 :(得分:1)
您的保存方法应如下所示:
function save(){
//echo "<pre>";
//print_r($this->input->post()); //first try to check whether you are receiving posted data or not.
//die;
$id_c= $this->input->post('id_c');
$idb = implode(',', $id_c);
$tanggal = $this->input->post('tanggal');
$data=array(
'id_c'=>$idb,
'tanggal'=>$tanggal
);
$this->db->insert('detail', $data);
}