RESOLVED Adding an extra element to an array on a text array
Posted: Mon Oct 22, 2012 6:32 pm
I'm listing out a bunch of products from a database using a while loop and next to it I'm placing the quantity of products. I want to be able to update the quantity, so I've placed it inside of an input field. I've used an array for the input name so that i can grab all of the entries from the while loop. however i want to add more than just the quantity to the array entries.
This will put the quantity into the array.
What i want to do is that when the array is received via $_POST i want it to have the product id ( $pro['product_id'] ) followed by the quantity but i only want the value of the text input to show quantity. I can separate the id from the quantity later that's no problem
on the other side want to use this but naturally all that goes through is quantity right now so this wont work
someone suggested using
but all i get is "Array"
if what im trying to do is not possible with arrays is there another way i can do this?
Code: Select all
<?php while ($pro = mysql_fetch_array($querypr, MYSQL_ASSOC)) { ?>
<input type="text" name="product[]" value="<?=$pro['product_quantity']?>" required>
<?php }What i want to do is that when the array is received via $_POST i want it to have the product id ( $pro['product_id'] ) followed by the quantity but i only want the value of the text input to show quantity. I can separate the id from the quantity later that's no problem
on the other side want to use this but naturally all that goes through is quantity right now so this wont work
Code: Select all
foreach ($_POST['product'] as $p){
echo "The product is ".substr($p,0,3)." and the quantity is ".substr($p,3)."<br>";
} Code: Select all
<input type="text" name="product[$pro['product_id']][]" value="<?=$pro['product_quantity']?>" required>if what im trying to do is not possible with arrays is there another way i can do this?