/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] adding extra value to text input array

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.

[code=html]<input type=”text” name=”product[]” value=”<?=$pro[‘product_quantity’]?>” required>[/code]

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

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@simplypixieOct 22.2012 — Try this
[code=php]<input type="text" name="product[$pro['product_id']][]" value="<?=$pro['product_quantity']?>" required>[/code]
Copy linkTweet thisAlerts:
@Da_ElfauthorOct 22.2012 — on the other side im using
[code=php]$products = $_POST['product'];
foreach ($products as $p){
echo $p."<br>";
}[/code]


i was going to seperate them via substr. how do i get my info now? all im getting is

Array

i need it to give something like

0011

0021

0035

00422

where the first 3 numbers are the product id and the last number(s) is the quantity
Copy linkTweet thisAlerts:
@Da_ElfauthorOct 22.2012 — i thought that method would just set the array so that the product_id is the key and the value is the value of the key. which i cant see would work

rather than trying to fix something that doesnt seem to work. is there another way around this?
Copy linkTweet thisAlerts:
@Da_ElfauthorOct 23.2012 — for anyone who is interested. this is how i resolved it
[code=php]<?php
if(isset($_POST['update'])){
foreach ($_POST['product'] as $p){
echo $p['product_id']." is the id and ".$p['product_quantity']." is the quantity<br>";
}
}
$sqlpr = "SELECT product_id, product_quantity FROM products WHERE order_id = '$myorder' ORDER BY product_id";
$querypr = mysql_query($sqlpr, $myCon);?>
<form name="cartform" action="cart.php" method="post">
<?php
$pad = 0;
while ($pro = mysql_fetch_array($querypr, MYSQL_ASSOC)) {?>
<input type="text" name="product[<?=$pad?>][product_quantity]" value="<?=$pro['product_quantity']?>" required><input type="hidden" name="product[<?=$pad?>][product_id]" value="<?=$pro['product_id']?>"/><br>
<?php $pad++; } ?>
<input name="update" type="submit" value="update" />
</form>[/code]
×

Success!

Help @Da_Elf spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...