Jump to content

[SOLVED] Connecting POST arrays


ryeman98

Recommended Posts

So I've got a shop and I need it to update multiple item prices at once but can't figure out how to connect the proper item to the proper price:

 

Form:

		echo "<form action='yourshop.php?act=changeprices' method='post'>";
	echo "<input type='hidden' name='shop_id' value='".$shop_id."'>";
	echo "<table align='center' width='100%' border='0' cellspacing='0' cellpadding='2'>";
	echo "<tr bgcolor='#000066' style='color:#FFFFFF;'><th width='20%'>Item</th><th width='5%'>QTY</th><th width='20%'>Name</th><th width='40%'>Description</th><th width='10%'>Price</th><th width='5%'>Remove</th></tr>";
	while ($row2 = mysql_fetch_array($items)) {
		$itemname = $row2['item'];
		$item_info = mysql_query("SELECT `description` FROM `items` WHERE name='$itemname'");
		$item = mysql_fetch_array($item_info);
		echo "<tr bgcolor='#CCCCCC'>";
		echo "<td><img style='border: 1px solid #000000;' src='../images/items/".strtolower($row2['item']).".gif'></td>";
		echo "<td>".$row2['COUNT(item)']."</td>";
		echo "<td><input type='hidden' name='item[]' value='".$row2['item']."'>".$row2['item']."</td>";
		echo "<td>".$item['description']."</td>";
		echo "<td><input type='textbox' name='price[]' size='7' maxlength='9' value='".$row2['price']."' /></td>";
		echo "<td><input type='checkbox' name='remove[]' value='".$row2['item']."' /></td>";
		echo "</tr>";
	}
	echo "<tr bgcolor='#000066' style='color:#FFFFFF;'><td colspan='6'><input type='submit' value='Update Shop'></td></tr>";
	echo "</table>";
	echo "</form>";

 

Process

foreach ($_POST['item'] as $item) {
foreach($_POST['price'] as $price) {
	$update = mysql_query("UPDATE `ushop_items` SET `price`='$cost' WHERE shop_id='$shop_id' AND item='$item'");
} // End loop
} // End loop

Link to comment
Share on other sites

Your description of your problem is pretty unhelpful, and why would you be executing queries within loops?

 

Ok. Say there are 3 different items in a form. Once they're sent to process, the loop will go through each item and change their prices accordingly.  What's happening is that it's taking the last price (each item is a different price) and changing them all to that price.  What it needs to do is change each price separately but I can't figure out how to connect the item to the price.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.