Jump to content

Removing items from database by a certain number?


djfox

Recommended Posts

I have the following code:

<?php
if ($lev > 0){
echo "<p>";

$res = mysql_query("SELECT id, name, excit, excam, exc FROM clothing WHERE id=$it");
$item = mysql_fetch_row($res);
mysql_free_result($res);

$res2 = mysql_query("SELECT id, name FROM collection WHERE id=$item[2]");
$item2 = mysql_fetch_row($res2);
mysql_free_result($res2);

$res3 = mysql_query("SELECT COUNT(*) FROM coll_inven WHERE item=$item[2] AND user='$loggeduser'");
$count = mysql_fetch_row($res3);
mysql_free_result($res3);

if ($item[4] == 1) {
if ($count[0] >= $item[3]) {

}
elseif ($count[0] < $item[3]){
$more = $item[3] - $count[0];
echo "<p>You don`t have enough <b>$item2[1]</b>. You need <b>$more</b> more to make the exchange.";	
}
}
elseif ($item[4] ==0){
echo "This is not an exchange item!";
}

}
?>

 

What this page should do is check to see if someone has enough of a certain item in their inventory to make an exchange. If they don`t have enough, the exchange is not made, but if they do have enough, the exchange needs to take place. The code would need to delete the number of items needed ($item[3]) from coll_inven.

 

Example:

Item the person wants to exchange for is Disco Ball ($item[1])

They need 5 ($item[3]) glass shards ($item[2]/$item2[1])

The person has 5 ($count[0]) in their inventory

So

5 ($item[3]) glass shards ($item[2]) from coll_inven that belong to the logged in person ($loggeduser) need to be deleted from the database.

 

How will I tell the code to delete only 5 ($item[3]) entries in coll_inven where item=$item[2] and user=$loggeduser ? Will I be using LIMIT=$item[3] ?

Link to comment
Share on other sites

I tried this:

mysql_query("DELETE FROM coll_inven2 WHERE item=$item[2] AND user='$loggeduser' LIMIT $item[3] ;"); or die(mysql_error());

 

But I get this error:

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/secrett1/public_html/exchange3.php on line 83

 

(Line 83 is the line above.)

 

I`m using coll_inven2 (with some play entries) to run tests for the code so that I don`t cause anything disastrous to happen to the real info.

Link to comment
Share on other sites

mysql_query("DELETE FROM coll_inven2 WHERE item=$item[2] AND user='$loggeduser' LIMIT $item[3]") or die(mysql_error());

 

Fix'd.

 

You had a ; in a bad place.

 

Also, don't put ;'s inside mysql_query() - unnecessary

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.