duannai1883 2017-09-09 23:16
浏览 132
已采纳

如何从php中的动态文本输入中获取两个值?

In my form I’m looping a recordset and storing the values using the naming convention within brackets [ ]. This nicely creates an Array but only stores the inputs value producing the results: 2, 1, 1

QTY: <input name="1pcCB['<?php echo $row_rs_type1['productname']; ?>']" type="text" id="<?php echo $row_rs_type1['productname']; ?>" value=""  />
<?php echo $row_rs_type1['productname']; ?>

How would I properly set the Array to ALSO have the unique ‘productname’ and the entered Value (Qty) from the input?

implode works nicely but only give the inputs values and not the productname

<?php  $capture_field_vals ="";
if(isset($_POST["1pcCB"]) && is_array($_POST["1pcCB"])){
 echo $capture_field_vals = implode(",", $_POST["1pcCB"]); 
}  
?>

The goal is to have the Product Name and the Qty comma separated as a single final value. How would this be achieved?

Final result should be the Product Names and the Value from the Input which is a Qty such as:

ProductNameX 2, ProductNameY 1, ProductNameZ 1

UPDATE:

print_r($_POST["1pcCB"]);

Array
(
    ['XL88ZM'] => 2
    ['XL88JB'] => 1
    ['XL22'] => 1
    ['XL88GB'] => 
    ['XL88Q'] => 
    ['XL301'] => 
    ['XL2050'] => 
    ['XL303'] => 
    ['XL3060'] => 
    ['XLWP'] => 
)

Using :

echo http_build_query($_POST["1pcCB"],'',', ');

Produces:

%27XL88ZM%27=2, %27XL88JB%27=3, %27XL22%27=6, %27XL88GB%27=, %27XL88Q%27=, %27XL301%27=, %27XL2050%27=, %27XL303%27=, %27XL3060%27=, %27XLWP%27=

I just need strip out the ones with no qty and get rid of the "%27" characters.

  • 写回答

1条回答 默认 最新

  • duanmei4362 2017-09-10 00:31
    关注

    Try like below.

    foreach ($_POST["1pcCB"] as $key => $value)
      $temp[] = "$key $value";
    
    $capture_field_vals = implode(",", $temp); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算