Page 1 of 1

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

Posted: Wed Feb 22, 2006 3:23 am
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.

Posted: Wed Feb 22, 2006 5:36 pm
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.

Posted: Thu Feb 23, 2006 2:57 am
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.