Reputation: 719
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.
Upvotes: 0
Views: 96
Reputation: 564
Try like below.
foreach ($_POST["1pcCB"] as $key => $value)
$temp[] = "$key $value";
$capture_field_vals = implode(",", $temp);
Upvotes: 1