简体   繁体   English

插入多个相同的输入名称字段Codeigniter

[英]Insert multiple same input name field codeigniter

id userid fldWorkHistoryCompanyName fldWorkHistoryJoiniedDate id用户id fldWorkHistoryCompanyName fldWorkHistoryJoiniedDate
1 1 abc company 2016.12.03 1 1 abc公司2016.12.03
2 1 def company 2017.12.03 2 1 def公司2017.12.03
3 1 ghi company 2018.12.03 3 1 GHI公司2018.12.03
4 2 ask company 2014.12.03 4 2问公司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 如何在codeigniter中插入多个名称

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. 您可以使用POST方法创建一个表单,并将这些字段放入表单中,并在提交按钮时将操作放入控制器中。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM