Php 如何通过foreach循环发送多个filed值?

Php 如何通过foreach循环发送多个filed值?,php,html,Php,Html,如何使用相同的ID,通过foreach循环发送多个字段值 这个HTML代码有什么问题 <input type="text" size="3" name="new_quantity[<?php echo $product_id; ?>]" value="<?php echo $product_quantity; ?>" /> <input type="text" name="totalcost[<?php echo $product_id; ?>

如何使用相同的
ID
,通过foreach循环发送多个字段值

这个HTML代码有什么问题

<input type="text" size="3" name="new_quantity[<?php echo $product_id; ?>]" value="<?php echo $product_quantity; ?>" />
<input type="text" name="totalcost[<?php echo $product_id; ?>]" value="<?php $total_cost; ?>"  />

循环中的循环将为您提供n*n次更新查询

但实际上您需要更新查询n次

这样做:

$pids     = array_keys($_REQUEST['new_quantity']); /// here you will get all product_ids

for($i=0; $i<count($_REQUEST['new_quantity']);$i++){
   echo $_REQUEST['new_quantity'][$pids[$i]]; // this quantity
   echo $_REQUEST['totalcost'][$pids[$i]]; // total cost
   echo $pids[$i]; // product id

   /// add your update query here all details you need in query are echoed above.
}
$pids=array_key($_请求['new_数量]);//在这里,您将获得所有产品标识

对于($i=0;$i尝试做一件事,为数量制作一个数组,为成本制作一个数组


然后在answe编辑的循环中启动更新查询,请立即检查所有值都将附加在数组中,并带有连续的标记您不需要
,因为
$qt[]=$quantity;
这将起作用
$pids     = array_keys($_REQUEST['new_quantity']); /// here you will get all product_ids

for($i=0; $i<count($_REQUEST['new_quantity']);$i++){
   echo $_REQUEST['new_quantity'][$pids[$i]]; // this quantity
   echo $_REQUEST['totalcost'][$pids[$i]]; // total cost
   echo $pids[$i]; // product id

   /// add your update query here all details you need in query are echoed above.
}
$qt=array();
foreach($_REQUEST['new_quantity'] as  $key => $quantity) {
$qt[].=$quantity;
}

$ct=array();
foreach($_REQUEST['totalcost'] as $key => $total) {
$ct[].=$total;
}