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 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线