Php 从发布的数组中提取所有表单值

Php 从发布的数组中提取所有表单值,php,Php,我有以下表格: <form method="post" action="mypage.php" orderform="" name="" id="orderform"> <a id="add">+</a> <table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable"> <tbody> <tr> <td

我有以下表格:

<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
 <table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
  <tbody>
    <tr>
      <td width="33%">Product Code (e.g 66203)</td>
      <td width="33%">mtrs sq Required (e.g 10)</td>
      <td width="33%">Preview Image</td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
      <td class="imgsample"></td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
      <td class="imgsample"></td>
    </tr>
    </tbody>
  </table>
  <button>Submit</button>
</form>

+
产品代码(例如66203)
要求的mtrs平方米(例如10)
预览图像
提交
我正在尝试接收帖子并打印关联产品价值及其计量…如下(这似乎只返回最后一个结果)有什么想法吗

    $number_of_products=count($_POST['prodcode']);
   for ( $i=0; $i<$number_of_products; $i++){
       $orderdetails = $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
   }
$number\u of_products=计数($\u POST['prodcode']);

对于($i=0;$i请尝试为输入字段上的
prodcode[]
meterage[]
名称编制索引,即:

<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
 <table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
  <tbody>
    <tr>
      <td width="33%">Product Code (e.g 66203)</td>
      <td width="33%">mtrs sq Required (e.g 10)</td>
      <td width="33%">Preview Image</td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode_0" name="prodcode[0]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage_0" name="meterage[0]"></td>
      <td class="imgsample"></td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode_1" name="prodcode[1]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage_1" name="meterage[1]"></td>
      <td class="imgsample"></td>
    </tr>
    </tbody>
  </table>
  <button>Submit</button>
</form>

+
产品代码(例如66203)
要求的mtrs平方米(例如10)
预览图像
提交

尝试为输入字段上的
prodcode[]
meterage[]
名称编制索引,即:

<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
 <table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
  <tbody>
    <tr>
      <td width="33%">Product Code (e.g 66203)</td>
      <td width="33%">mtrs sq Required (e.g 10)</td>
      <td width="33%">Preview Image</td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode_0" name="prodcode[0]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage_0" name="meterage[0]"></td>
      <td class="imgsample"></td>
    </tr>
    <tr class="item">
      <td class="prodcode "><input type="text" id="prodcode_1" name="prodcode[1]" class=" "></td>
      <td class="meterage"><input type="text" id="meterage_1" name="meterage[1]"></td>
      <td class="imgsample"></td>
    </tr>
    </tbody>
  </table>
  <button>Submit</button>
</form>

+
产品代码(例如66203)
要求的mtrs平方米(例如10)
预览图像
提交

每次运行for循环时都会覆盖$orderdetails的内容

试着这样做:

$number_of_products=count($_POST['prodcode']);
$orderdetails = "<h1>Order Details</h1>";
for ( $i=0; $i<$number_of_products; $i++){
       $orderdetails .= $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
$number\u of_products=计数($\u POST['prodcode']);
$orderdetails=“订单详细信息”;

对于($i=0;$i),每次运行for循环时都会覆盖$orderdetails的内容

试着这样做:

$number_of_products=count($_POST['prodcode']);
$orderdetails = "<h1>Order Details</h1>";
for ( $i=0; $i<$number_of_products; $i++){
       $orderdetails .= $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
$number\u of_products=计数($\u POST['prodcode']);
$orderdetails=“订单详细信息”;

对于($i=0;$i它,因为您每次都会覆盖它 改变 $orderdetails= 到
$orderdetails.=

因为您每次都会覆盖它 改变 $orderdetails= 到
$orderdetails.=

我需要保持数组的原样,但感谢您的输入!非常感谢。我需要保持数组的原样,但感谢您的输入!非常感谢。没问题。有时需要多用一双眼睛才能捕捉到这样的东西。没问题。有时需要多用一双眼睛才能捕捉到这样的东西。