Codeigniter 插入动态多输入

Codeigniter Insert Dynamic multiple input

有人可以帮助我吗?我有货。你能帮我如何从多个动态文本框中保存多个值吗?

我的观点:

 <?php
  echo form_open(admin/add_transaction); 
  for ($i=0; $i < $qty ; $i++) { 
  $count = $i+1; 
  $newinput=array(
     'class'=>"form-control",
     'name'=>"$property_no-$count",
     'placeholder'=>"Serial No. - $property_no-$count",
                 ); ?>
                               <div class="input-group">
                               <span class="input-group-addon">
                               <i class="glyphicon glyphicon-barcode"></i></span>
                              <?php echo form_input($newinput); ?></div>
                               <br>
                               <?php }
                               echo form_close();
                                ?>

我的控制器:

        function add_transaction(){
        $this->masterrecords->save_serial();
        redirect('admin/transaction');
    }

我的模型:如何插入输入文本的多个值?

        function save_serial(){

        $s=$this->input->post('new');

        $data = array();
    for ($i = 0; $i < count($this->input->post('new')); $i++)
    {
        $data = array(

            'serial_no' => $s[$i],


        );
    }
        $this->db->insert('tblserial_no' ,$data);
        return true;



    }

你有 $qty$property_no 变量..你可以做的是为这两个变量创建两个隐藏字段:

 <input type='hidden' name='qty' value='<?= $qty ?>'/>
 <input type='hidden' name='property_no' value='<?= $property_no ?>'/>

 //then in your model:
 $data = array();
 for ($i=0; $i < $this->input->post('qty') ; $i++) { 

       $count = $i+1;

       //check fields are set and not empty...
       if($this->input->post($this->input->post('property_no').'-'.$count) && 
          $this->input->post($this->input->post('property_no').'-'.$count) != ""){

          //prepare your $data array.. 
          $data[$count] = $this->input->post($this->input->post('property_no').'-'.$count);

       }
  }

希望这可能会给您一些想法或解决您的问题..也..

如果我的回答对您有帮助可以标记为答案,谢谢