each($_POST["separator"])) for more than one post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

each($_POST["separator"])) for more than one post

Post by rsmarsha »

Code: Select all

while(list($prod, $sep) = each($_POST["separator"]))
{
		$sep = "UPDATE form_products SET separator='$sep' WHERE form_id='$_POST[id]' AND form_product='$prod'";
		$sepq = mysql_query($sep) or die ("Query $sep Failed".mysql_error());
}
The above code takes a series of posts with the same variable name and runs an update using each one. I want to do the same but with 2 $_POST's, would i have to have 2 loops so that each post had one. Or is there a way of having that loop working both. Each post will have the same amount number of itself posted.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Perhaps if you showed some example form code and what the values look like it would be easier to understand what is going on.
(#10850)
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

This is some of the form code:

Code: Select all

<td align="center"><input type="text" size="3" name="<?php echo 'cust['.$lrow['product_id'].']'; ?>" id="cust" value="<?php echo ''.$lrow['customer_price'].''; ?>"></td>
<td align="center"><input type="text" size="3" name="<?php echo 'buy['.$lrow['product_id'].']'; ?>" id="buy" value="<?php echo ''.$lrow['buy_price'].''; ?>"></td>
This code runs through the first input from the form:

Code: Select all

while(list($prod, $sep) = each($_POST["cust"]))
{ 
	echo 'TEST: '.$prod.' = '.$sep.'<br />';
}
Where the echo currently exists i will enter an update query. I need to work out how to add the 2nd form input to that loop and therefore the query.

As it is now i could do another loop for the 2nd variable and it would work, but i'm wanting to get it all into one loop and one query in the end. The problem isn't with the query it's getting the loop to go through all the variables at the same time.
Post Reply