我有一个带复选框的电子邮件列表,看起来像这样
我希望该用户能够选择多个值,然后将其保存在数据库中
查看
<?php
$reg_attributes = array('id'=>'form','class'=>'form-horizontal');
echo form_open('admin/assignrec/'.$data->id, $reg_attributes);
foreach($client as $rec_id): ?>
<tr>
<td> <?php echo form_checkbox('recid[]', $rec_id->id); ?> </td>
<td><?php echo $rec_id->email; ?></td>
</tr>
<?php
endforeach;
echo form_close();
?>
控制器
public function assignrec($dataid)
{
$chk = $this->input->post('recid');
$this->admin_model->assign_rec($quickdataid) ;
}
模型
public function assign_rec($dataid)
{
foreach ($chk as $chkid)
{
$data = array(
'requestid' => $dataid,
'recruiterid' => $this->input->post('chkid')
);
}
$insert_request = $this->db->insert('rec', $data);
return $insert_data;
}
但是我无法在数据库中保存值,任何人都可以帮助我
答案 0 :(得分:0)
您的控制器应该像
public function assignrec($dataid)
{
$quickdataid= $this->input->post('recid');
$this->admin_model->assign_rec(dataid,$quickdataid) ;
}
您的模型应该像
public function assign_rec($dataid,$chk)
{
foreach ($chk as $chkid)
{
$data = array(
'requestid' => $dataid,
'recruiterid' => $this->input->post('chkid')
);
}
$insert_request = $this->db->insert('rec', $data);
return $insert_data;
}