id用户ID fldWorkHistoryCompanyName fldWorkHistoryJoiniedDate
1的1的abc公司abc公司2016.12.03
2的1的def公司的公司2017.12.03
3的1的ghi公司的2018年12月3日
4,2,问公司,2014年12月3日
<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="ABC Privet Limited 1" >
<input type="text" class="form-control" name="fldWorkHistoryJoiniedDate[]" >
<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="ABC Privet Limited 2" >
<input type="text" class="form-control" name="fldWorkHistoryJoiniedDate[]" >
<input name="fldWorkHistoryCompanyName[]" type="text" class="form-control" placeholder="ABC Privet Limited 3" >
<input type="text" class="form-control" name="fldWorkHistoryJoiniedDate[]" >
如何在codeigniter中插入多个名称
答案 0 :(得分:0)
为了使用单个名称在数据库中插入多个输入文本值。
您可以使用POST方法创建一个表单,并将这些字段放入表单中,并在提交按钮时将操作放入控制器中。
在控制器中,您可以
$history[] = $_Post['fldWorkHistoryCompanyName'];
foreach ($history as $key => $value) {
// make insert query and your value is in the $value variable.
}
OR
如果您有活动记录,则可以执行以下操作:
$data = array(
array(
'userid' => '1' ,
'fldWorkHistoryCompanyName' => 'Name' ,
'fldWorkHistoryJoinedDate' => 'My date'
),
array(
'userid' => '2' ,
'fldWorkHistoryCompanyName' => 'Another Name' ,
'fldWorkHistoryJoinedDate' => 'Another date'
)
);
$this->db->insert_batch('mytable', $data);
答案 1 :(得分:0)
尝试一下:
$fldWorkHistoryCompanyName = $this->input->post('fldWorkHistoryCompanyName');
foreach ($fldWorkHistoryCompanyName as $value) {
$data = array(
'field_name' => $value
);
$this->db->insert('tableName',$data);
}
答案 2 :(得分:0)
您可以尝试以下解决方案:
$i = 0
Foreach($fldWorkHistoryCompanyName as $key=>$value)
{
$data[$i]['fldWorkHistoryCompanyName'] = $value;
$data[$i]['fldWorkHistoryJoiniedDate'] = $fldWorkHistoryJoiniedDate[$key];
$i++;
}
$this->db->insert_batch('table_name',$data);