arrays - Insert Multiple records in codeigniter using checkboxes -


i have 2 input arrays 1 checkbox , and 1 textbox

which view file

<div class="form-group">         <label class="col-lg-2 control-label">fee types</label>         <div class="col-lg-8">         <div class="checkbox">         <?php foreach($types $key=>$value){?>              <label>                 <input type="checkbox"  value="<?php echo $value['id'] ?>"  name="type_id[]" />                 <span class="text"><?php echo $value['name'] ?></span>             </label>             <input type="text"  class="form-control"  name="amount[]" />             <?php } ?>         </div>         </div>     </div> 

which controller

$data=array(                     'id'=>$this->input->post('id'),                     'amount'=>$this->input->post('amount'),                     'type_id'=>$this->input->post('type_id'),                     'created_date'=>date('y-m-d'),                     );                     $this->user->details($data); 

could tell me how insert 2 arrays multiple records

$checkboxes = $this->input->post('type_id[]'); $amounts= $this->input->post('amount[]');  ($i = 0; $i < count($amounts); $i++) {    $data = array(        'id'=> $youridpostfield,        'amount'=>$amounts[$i],        'type_id'=> $checkboxes[$i],        'created_date'=>date('y-m-d'),    );    $this->user->details($data); } 

this simple way... maybe problem no checkbox post data becouse not checked, if want problem add increment number form ...

<div class="form-group">         <label class="col-lg-2 control-label">fee types</label>         <div class="col-lg-8">         <div class="checkbox">         <?php foreach($types $key=>$value){?>              <label>                 <input type="checkbox"  value="<?php echo $value['id'] ?>"  name="type_id[$key]" />                 <span class="text"><?php echo $value['name'] ?></span>             </label>             <input type="text"  class="form-control"  name="amount[<?php echo $key ?>]" />             <?php } ?>         </div>         </div>     </div>  

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -