Sinikka Posted November 30, 2009 Share Posted November 30, 2009 I'm trying to setup a trade system to where multiple items (up to 10) can be inserted into the same trade. Currently, I have it pulling the items properly and processing the trade but it's adding each item selected into separate trades rather then combining them into one lot. The code isn't fully functional by any means at the moment, I'm more focused on trying to get the lots working properly before I continue with the code. This is the coding that pulls the items into the creation page for the checkboxes. $getitems = mysql_query("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game' ORDER BY item_id LIMIT 10"); while ($getitems2 = mysql_fetch_array($getitems)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$getitems2[item_id]' AND game = '$game'"); $tradeID = $getitems2[id]; $tradelist .= " <TR BGCOLOR=\"$maincellColor\"> <TD WIDTH=35 HEIGHT=40> <CENTER><INPUT TYPE=checkbox NAME=trade_item[$tradeID] value=1></CENTER> </TD> <TD HEIGHT=40> <img src=$base_url/images/user_images/opg_$game/items/item_$get_item[id].gif height=40 width=40> <b>$get_item[item_name]</b><br> </TD> </TR> "; } And this is the processing code after they hit submit. $explodeTrade = explode(" ", $trade_item[$tradeID]); $countTrade = count($explodeTrade) - 1; for ($a = 0; $a <= $countTrade;) if ($Submit == "Create Trade!") { $getitems = mysql_query("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game'"); while ($getitems2 = mysql_fetch_array($getitems)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$getitems2[item_id]' AND game = '$game'"); $tradeID = $getitems2[id]; $endTime = $timestamp + $end_in; if ($trade_item[$tradeID] == 1) { mysql_query("INSERT INTO trades2 (item_name1,owner,end_time,date,wishlist,game) VALUES ('$trade_item[$tradeID]','$username','$endTime','$current_date','$wishlist','$game')"); mysql_query("DELETE FROM usersitems2 WHERE owner = '$userid' AND id = 'Not added yet to avoid deleting items' AND game = '$game'"); } } die(header(error("trade2.php?game=$game&page=search&search_by=my_trades","That item has been put into trade!"))); } Link to comment https://forums.phpfreaks.com/topic/183425-multiple-checkbox-input-insertion/ Share on other sites More sharing options...
Sinikka Posted November 30, 2009 Author Share Posted November 30, 2009 Ok I just managed to get it to insert more then one item into the trade but now it's duplicating the lot rather then just creating one. $getitems = mysql_query("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game' ORDER BY item_id LIMIT 10"); while ($getitems2 = mysql_fetch_array($getitems)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$getitems2[item_id]' AND game = '$game'"); $tradeID = $getitems2[id]; $itemList .= "<option value=$getitems2[id]>$get_item[item_name]"; $tradelist .= " <TR BGCOLOR=\"$maincellColor\"> <TD WIDTH=35 HEIGHT=40> <CENTER><INPUT TYPE=checkbox NAME=trade_item[] id=$tradeID value=$get_item[id]></CENTER> </TD> <TD HEIGHT=40> <img src=$base_url/images/user_images/opg_$game/items/item_$get_item[id].gif height=40 width=40> <b>$get_item[item_name]</b><br> </TD> </TR> "; } $explodeTrade = explode(" ", $trade_item); $countTrade = count($explodeTrade) - 1; for ($a = 0; $a <= $countTrade;) if ($Submit == "Create Trade!") { $getitems = mysql_query("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game'"); while ($getitems2 = mysql_fetch_array($getitems)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$getitems2[item_id]' AND game = '$game'"); $tradeID = $getitems2[id]; $endTime = $timestamp + $end_in; mysql_query("INSERT INTO trades2 (item_name1,item_name2,item_name3,item_name4,item_name5,item_name6,item_name7,item_name8, item_name9,item_name10,owner,end_time,date,wishlist,game) VALUES ('$trade_item[0]','$trade_item[1]','$trade_item[2]','$trade_item[3]','$trade_item[4]','$trade_item[4]', '$trade_item[6]','$trade_item[7]','$trade_item[8]','$trade_item[9]','$username','$endTime','$current_date','$wishlist','$game')"); mysql_query("DELETE FROM usersitems2 WHERE owner = '$userid' AND id = '$trade_item' AND game = '$game'"); } die(header(error("trade2.php?game=$game&page=search&search_by=my_trades","That item has been put into trade!"))); } Link to comment https://forums.phpfreaks.com/topic/183425-multiple-checkbox-input-insertion/#findComment-968264 Share on other sites More sharing options...
Sinikka Posted December 1, 2009 Author Share Posted December 1, 2009 Still looking for any suggestions on this if anyone has any. Link to comment https://forums.phpfreaks.com/topic/183425-multiple-checkbox-input-insertion/#findComment-969072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.