ryeman98 Posted June 20, 2009 Share Posted June 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/ Share on other sites More sharing options...
RussellReal Posted June 20, 2009 Share Posted June 20, 2009 try dis foreach ($_POST['item'] as $k => $v) { $price = $_POST['price'][$k]; $item = $v; // do query here } Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860035 Share on other sites More sharing options...
ryeman98 Posted June 20, 2009 Author Share Posted June 20, 2009 try dis foreach ($_POST['item'] as $k => $v) { $price = $_POST['price'][$k]; $item = $v; // do query here } That really doesn't do anything. Item is a string and price is an integer. Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860043 Share on other sites More sharing options...
trq Posted June 20, 2009 Share Posted June 20, 2009 Your description of your problem is pretty unhelpful, and why would you be executing queries within loops? Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860044 Share on other sites More sharing options...
ryeman98 Posted June 20, 2009 Author Share Posted June 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860045 Share on other sites More sharing options...
ryeman98 Posted June 20, 2009 Author Share Posted June 20, 2009 Fixed, turns out it was just a mistake on my part. Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860050 Share on other sites More sharing options...
trq Posted June 20, 2009 Share Posted June 20, 2009 Fixed, turns out it was just a mistake on my part. Obviously. Who's fault did you think it would be? Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860052 Share on other sites More sharing options...
ryeman98 Posted June 20, 2009 Author Share Posted June 20, 2009 Fixed, turns out it was just a mistake on my part. Obviously. Who's fault did you think it would be? Yours. Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860053 Share on other sites More sharing options...
trq Posted June 20, 2009 Share Posted June 20, 2009 You would. Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860055 Share on other sites More sharing options...
ryeman98 Posted June 20, 2009 Author Share Posted June 20, 2009 You would. Glad to get back in the game, I haven't programmed php for months! Quote Link to comment https://forums.phpfreaks.com/topic/162992-solved-connecting-post-arrays/#findComment-860056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.