duannai1883 2017-09-09 15: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-09 16:31
    关注

    Try like below.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部