2016-03-08 65 views
0

有人可以幫助我。即時股票。你能幫我怎麼從多個動態文本框中保存多個值嗎?Codeigniter插入動態多輸入

筆者認爲:

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



    } 

回答

0

你有$qty$property_no與you..what你可以做的變量是創建兩個隱藏字段兩個變量:

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

     } 
    } 

希望,這可能給你一些想法或可能會解決你的問題..太..

如果我的答案可以幫助你把它標記爲答案,謝謝。