我有一个表格由多个复选框,输入字段,我想这些数据插入到表中的一列,这是我的形式:如何在笨插入一列多个字段的数据
<div id="container">
<h1>property Detail</h1>
<form action="" method="post">
<table>
<tr>
<td>
Possesion
<input type="checkbox" name="feature[]" value="possesion">
</td>
<td>
Possesion1
<input type="checkbox" name="feature" value="possesion1">
</td>
<td>
Possesion2
<input type="checkbox" name="feature" value="possesion2">
</td>
<td>
Possesion3
<input type="checkbox" name="feature" value="possesion3">
</td>
<td>
Possesion4
<input type="checkbox" name="feature" value="possesion4">
</td>
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</div>
这里是我的控制器:
function index(){
$this->load->view('form');
if($_POST){
$data_feature = array (
'feature' => $_POST['feature']
);
$data['var']= $this->Mdata->p_detail($data_feature);
}
}
,这里是我的模型:
function p_detail($data_feature){
$this->db->insert('feature',$data_feature);
return $this->db->insert_id();
}
我只得到我的表中有一个特征值,我想获取用户选中的复选框的所有值。
问候
首先改变'NAME =“功能”'到'名字=“功能[]”'所有复选框元素,然后通过很多关系价值控制器。并在此之后'implode()'函数将数组值转换为字符串并在数据库表字段中保存为逗号分隔值。希望能帮助到你!!! –
如何将数组值转换为字符串 –
在Google中输入精确的句子,并且还可以看到我的评论:) –