Foreach Help

Hi guys i just want to be able to add this form to a mysql update command
E.g.

mysql_query("UPDATE table SET product_quantity = ‘.$product_count.’ WHERE product_id = ‘.$product_id.’ ");

for each array.

I done some test below just to see how it is processed… i need it to add like… Q then P then Q then P.

Im not sure how to do it, i tried adding two foreach commands inside each other although that came up with 3 times the results.
I was trying to add two foreach in one statement so i could reference to both at the same time.

All help would be great.

Thanks!

Q:13
Q:1
Q:1
Q:12
P:3
P:5
P:1
P:4

[php]include_once(‘content/page_header.php’);

//POST VARS
$quantity_post = $_POST[‘quantity’];
$product_post = $_POST[‘product_id’];

$string = “”;

foreach($quantity_post as $quantity){
$string .= “Q:”.$quantity."
";
}
foreach($product_post as $product){
$string .= “P:”.$product."
";
}

echo $string;
[/php]

Is each q and p going on its own row or does each q and each p on a row?

using your example

row 1 Q:13
row 2 Q:1
row 3 Q:1
row4 Q:12
row 5 P:3
row 6 P:5
row 7 P:1
row 8 P:4

or

row 1 Q:13, Q:1, Q:1, Q:12
row 2 P:3, P:5, P:1, P:4

Something like either one of those?

Yea it was the second one but ive found one answer that works! Thanks

Lot of extra code when all u needed was implode().

Sponsor our Newsletter | Privacy Policy | Terms of Service