2

データベースからの製品データがあり、編集フォームで入力の値を設定しようとしていますが、for および foreach ループを管理する方法がわかりません :( ここに私が試しているコードがあります

<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 は配列になります。これを達成する方法を教えてください。事前に感謝します

4

1 に答える 1

0

$r ループは不要であり、データを何度も実行しています。

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

正直なところ、データをモデルに送り返すのは少し頭の痛い問題になると思いますが、個人的には、1 つのページで複数のことをしようとするのではなく、製品をリストしてから、それぞれに独自の編集ページを与えます。

于 2012-10-28T10:30:03.157 に答える