Jump to content
MakeWebGames

Help with item add


boots

Recommended Posts

Im trying to cahnge this line using item_add

INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES (123, :myid:, 1)

this is what i have i have. Tried so many ways but still cant get it to work can somone please put me right

item_add($userid, $r['itemid 123 ], $r['imQTY 1']);

Link to comment
Share on other sites

The way the line is at the moment it sends the item to the inventory but as single items so i have a list of the same item but i want them to be added to one group

i have used item_add before but cant seem to get it to work this time :(

the line I want to change is

INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES (123, :myid:, 1)

Edited by boots
Link to comment
Share on other sites

EDIT:

Here's how my function's set up. A bit different, I think, since it's V1, but it adds the right quantity.

 

function item_give($userid, $itemid, $qty, $notid=0)
{
 if($notid > 0)
 {
   $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$userid} and inv_itemid={$itemid} AND inv_id != {$notid}");
 }
 else
 {
   $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$userid} and inv_itemid={$itemid}");
 }
 if(mysql_num_rows($q) > 0)
 {
   $r=mysql_fetch_array($q);
   mysql_query("UPDATE inventory SET inv_qty=inv_qty+{$qty} WHERE inv_id={$r['inv_id']}");
 }
 else
 {
   mysql_query("INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES ({$itemid}, {$userid}, {$qty})");
 }
}
Link to comment
Share on other sites

The way the line is at the moment it sends the item to the inventory but as single items so i have a list of the same item but i want them to be added to one group

i have used item_add before but cant seem to get it to work this time :(

the line I want to change is

INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES (123, :myid:, 1)

If I recall correctly v2's item_add function automatically updates the inv_qty of an item already existing in a users inventory.

Mind sharing your item_add function?

Link to comment
Share on other sites

Yes it does update automatically but i cant remember how to rewite the line

INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES (123, :myid:, 1)

instead of insert into inventory i think it should be item_add

Link to comment
Share on other sites

item_add($userid, $r['itemid 123 ], $r['imQTY 1']);

Your issue is this $r[itmid 123'], $r['imQTY 1']

Not how it works your dont specify the itemid and qty there as its already been done in the query before that

item_add($userid, $r['itemid], $r['imQTY']);

Is all you require for the function.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

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