Damond Posted June 10, 2015 Posted June 10, 2015 My game has been up and running live for almost two months now, 850+ accounts and counting. So like a good admin I have been listening to my players suggestions and implementing the good ones as quickly as I can. I've come to one that is giving me a bit of problem so I turn back to the MWG community to point me in the right direction. In the item market file there is already coding to remove items that you have placed on the market. What if you have several items and want to remove them all at once? Its a real pain looking through a massive listing for each of your items and pulling them one at a time. Enter the Remove All button. I have some coding in place but I keep getting only one item removed.. Granted I don't have to look for my items it just removes them one after another as I keep clicking the button, but its still not doing what it should. First the switch case: case "removeall": remove_all(); break; Then the code to show you the button or not $q2 = $db->query("SELECT * FROM itemmarket WHERE imADDER=$userid"); if ($db->num_rows($q2)>=1){ $r = $db->fetch_row($q2); print"<br><a href='itemmarket.php?action=removeall&ID={$r['imID']}' class='button'>Remove All</a><br>"; } Then my Remove all function: function remove_all() { global $db, $ir, $c, $userid, $h; $q = $db->query("SELECT im.*,i.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid WHERE imID={$_GET['ID']} AND imADDER=$userid"); if (!$db->num_rows($q)) { print "<div id=text3>Error, either this item does not exist, or you are not the owner.<br /> <a href='itemmarket.php'><strong>Back</strong></a>"; $h->endpage(); exit; } while ($ra = $db->num_rows($q)>0){ $r = $db->fetch_row($q); item_add($userid, $r['imITEM'], $r['imQTY']); $i = ($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$_GET['ID']}"); $db->query("INSERT INTO imremovelogs VALUES (NULL, {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} removed a ".$db->escape($r['itmname'])." from the item market.')"); } print "All item removed from market!<br /> <a href='itemmarket.php'><strong>Back</strong></a></div>"; } I feel like I am right there but just missing one little vital part that I just can't put my finger on. Quote
sniko Posted June 10, 2015 Posted June 10, 2015 (edited) You're looping through your results and re-adding the item to the user, which is correct. However, the part which is wrong is your SELECT statement to fetch listings by a user and your DELETE statement. I'm going to assume that imID is the primary autoincrement key, which means change your value from {$_GET['ID']} to {$ra['imID']} You're using while ($ra = $db->num_rows($q)>0){ which should become while ($ra = $db->fetch_array($q)){. (You can put the num_rows() check above the while.) function remove_all() { global $db, $ir, $c, $userid, $h; $q = $db->query("SELECT im.*,i.* FROM itemmarket im LEFT JOIN items i ON im.imITEM=i.itmid WHERE imADDER=$userid"); if (!$db->num_rows($q)) { print "<div id=text3>Error, either this item does not exist, or you are not the owner. <a href='itemmarket.php'><strong>Back</strong></a>"; $h->endpage(); exit; } while ($ra = $db->fetch_row($q)){ item_add($userid, $ra['imITEM'], $ra['imQTY']); $i = ($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM itemmarket WHERE imID={$ra['imID']}"); $db->query("INSERT INTO imremovelogs VALUES (NULL, {$ra['imITEM']}, {$ra['imADDER']}, $userid, {$ra['imID']}, $i, unix_timestamp(), '{$ir['username']} removed a ".$db->escape($ra['itmname'])." from the item market.')"); } print "All item removed from market! <a href='itemmarket.php'><strong>Back</strong></a></div>"; } Edited June 10, 2015 by sniko Quote
Damond Posted June 10, 2015 Author Posted June 10, 2015 [MENTION=65371]sniko[/MENTION] Perfect. Thank you very much it works like a charm. Quote
Magictallguy Posted June 11, 2015 Posted June 11, 2015 [...] You're using while ($ra = $db->num_rows($q)>0){ which should become while ($ra = $db->fetch_array($q)){. (You can put the num_rows() check above the while.)[...] v2: $db->fetch_row() ;) Quote
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.