Php 如何通过codeigniter中的循环在一列中插入多个字段数据
我有一个由多个复选框和输入字段组成的表单,我想将该数据插入到表的一列中的行中,这是我的表单:Php 如何通过codeigniter中的循环在一列中插入多个字段数据,php,codeigniter,loops,Php,Codeigniter,Loops,我有一个由多个复选框和输入字段组成的表单,我想将该数据插入到表的一列中的行中,这是我的表单: <div id="container"> <h1>property Detail</h1> <form action="" method="post"> <table> <tr> <td> Possesion <input type="checkbo
<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 p_detail($features){
$this->db->insert('feature',$features);
}
这将是通过循环,但我不知道如何确切地做到这一点??任何人都请帮帮我
问候
$feature_list = $_POST['feature[]'];
这是“获取文件列表”复选框
function p_detail($feature_list){
$data=array();
foreach($feature_list as $item){
array_push($data,
array('feature'=>$item));
}
return $this->db->insert_batch('feature',$data);
}
我希望这对你有用。你的问题是?你在
p\u detail
方法中的$features
得到了什么?你的问题是什么?它以json格式存储所有值。是的,它存储所有值并插入到表中,但我想插入行,而不是用逗号分隔的行json\u decode
,并使用循环插入我知道它将通过循环,但我不知道如何做复选框未选中时,不返回任何值。小心未定义索引功能[]将所有输入更改为name=“feature”
。和$feature\u list=$\u POST['feature']代码>
function p_detail($feature_list){
$data=array();
foreach($feature_list as $item){
array_push($data,
array('feature'=>$item));
}
return $this->db->insert_batch('feature',$data);
}