Jump to content
MakeWebGames

Remove all Items from market.


Damond

Recommended Posts

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.

Link to comment
Share on other sites

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 by sniko
Link to comment
Share on other sites

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.   Paste as plain text instead

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