Jump to content

PHP Foreach Help


lewisstevens1

Recommended Posts

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

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."<br/>";
}
foreach($product_post as $product){
	$string .= "P:".$product."<br/>";
}

echo $string;

Link to comment
https://forums.phpfreaks.com/topic/279569-php-foreach-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.