如何在PHP中使用foreach循环获取表中的多个文本框?

时间:2017-12-14 03:08:01

标签: php

<table>
<?php
   `extract($_POST);`
   `$objorderdetails = new Dairy_System();`

   `$result=$objorderdetails->getCustomerName();`

   foreach($result as $row)
   {
     $result1=$objorderdetails->getOrderDetails();
     foreach ($result1 as $row1)
     {
?>
<tr>   
  <td><?php echo($row['UserName']); ?></td>
  <td><input type="number" name="Quantity" value="<?php echo($row1['Quantity']); ?>">
  <?php
    if($row['Quantity']==NULL && $row['Quantity']==""){
      $row['Quantity']=0;
    }
  ?>
  </td>  
</tr>
<?php
    }
  }
?>
</table>

1 个答案:

答案 0 :(得分:0)

使用输入数组。例如,name="Quantity"

<table>
<?php
                    `extract($_POST);`
                    `$objorderdetails = new Dairy_System();`

                    `$result=$objorderdetails->getCustomerName();`

                  foreach($result as $row)
                  {
                    $result1=$objorderdetails->getOrderDetails();
                    foreach ($result1 as $row1)
                    {
                   ?>
                    <tr>   
                      <td><?php echo($row['UserName']); ?></td>
                      <td><input type="number" name="Quantity[]" value="<?php echo($row1['Quantity']); ?>">
                        <?php
                          if($row['Quantity']==NULL && $row['Quantity']==""){
                         $row['Quantity']=0;
                        }
                        ?>
                      </td>  
                    </tr>
                  <?php
                  }
                }
 ?>
</table>