2012-10-28 31 views
2

我有從數據庫的產品數據,並試圖設置編輯形式的輸入值,但不知道如何管理和foreach循環:(這裏是我想要的代碼CodeIgniter從數據庫形式的數據和輸入序列的設置值

<table id="dyTable"> 
     <thead> 
     <th style="width:20px; padding-right:10px;">No.</th> 
     <th style="width:70px; padding-right:10px;">Quantity</th> 
     <th style="width:290px; padding-right:10px;">Product</th> 
     <th style="width:100px; padding-right:10px;">Unit Price</th> 
     </thead> 
     <tbody> 

     <?php 

     for($r=1; $r<=$pr_value; $r++){ 
      foreach($inv_products as $prod): 

      $quantity.$r = array('name' => $quantity.$r, 
       'id' => $quantity.$r, 
       'type' => 'text', 
       'value' => $this->form_validation->set_value($prod->quantity), 
       'class'  => 'text', 
       'style' => 'width: 70px; text-align: center;' 
      ); 
      $product.$r = array('name' => $product.$r, 
       'id' => $product.$r, 
       'type' => 'select', 
       'value' => $this->form_validation->set_select($prod->product_id), 
       'class' => 'chzn-select', 
       'style' => 'width:300px;' 
      ); 
      $unit_price.$r = array('name' => $unit_price.$r, 
       'id' => $unit_price.$r, 
       'type' => 'text', 
       'value' => $this->form_validation->set_value($prod->unit_price), 
       'class'  => 'text', 
       'style' => 'width: 100px; text-align: right;' 
      ); 
      ?> 

       <tr id="line<?php echo $r; ?>"> 
       <td style="width: 20px; text-align: center; padding-right: 10px; padding-right: 10px;"><?php echo $r; ?></td> 
       <td><?php echo form_input($quantity.$r);?></td> 
       <td><?php echo form_dropdown($product.$r); ?></td> 
       <td><?php echo form_input($unit_price.$r);?></td> 
       </tr> 
      <?php 

      endforeach; 
     } 
     ?> 

     </tbody> 

現在$ R成爲一個陣列。任何想法如何實現this.Thanks提前

回答

0

的$ R循環是不必要的,你通過數據進行多次的方式在運行're doing it。

$r=0 
foreach($inv_products as $prod) 
{ 
    $r++ 
    //create your table rows here 
} 

儘管我誠實地認爲將數據發送回模型會讓人頭疼,但我個人列出了產品,然後給每個自己的編輯頁面,而不是嘗試在一個頁面上執行多個。

+0

我試過,但無法獲得所需的結果,然後我使用foreach將數據保存在不同的數組中,然後用於顯示值。謝謝 – Saleem

相關問題