id userid fldWorkHistoryCompanyName fldWorkHistoryJoiniedDate
1 1 abc company 2016.12.03
2 1 def company 2017.12.03
3 1 ghi company 2018.12.03
4 2 ask company 2014.12.03
<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[]" >
how to insert multiple name filed in codeigniter
</div>
In order to insert multiple input text values in database using single name.
You can make a form with method POST and put these fields into form and when you submit the button you can put the action into your controller.
In the controller, you can do
$history[] = $_Post['fldWorkHistoryCompanyName'];
foreach ($history as $key => $value) {
// make insert query and your value is in the $value variable.
}
OR
If you have active records then you can to do this:
$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);
try this:
$fldWorkHistoryCompanyName = $this->input->post('fldWorkHistoryCompanyName');
foreach ($fldWorkHistoryCompanyName as $value) {
$data = array(
'field_name' => $value
);
$this->db->insert('tableName',$data);
}
you can try this solution :
$i = 0
Foreach($fldWorkHistoryCompanyName as $key=>$value)
{
$data[$i]['fldWorkHistoryCompanyName'] = $value;
$data[$i]['fldWorkHistoryJoiniedDate'] = $fldWorkHistoryJoiniedDate[$key];
$i++;
}
$this->db->insert_batch('table_name',$data);