I've been working on this all night, and getting close but just can't quite get it right.
I'm trying to create a function that will first look at the items table, and then see if the player already has the item. If he does, it will perform the update query. If he doesn't it will perform the insert query.
It was working fine when I only had 1 record in the table, once I added more then one. it doesn't seem to do what I think it should. It inserts even tho a player already has the item.
I think the problem is my $itemcheck and the array. I don't think I wrote that right, but not sure.
Code: Select all
$itemcheck = mysql_query("SELECT * FROM items");
while($row = mysql_fetch_array($itemcheck))
{
if ( $item_number == "1")
{
$itemtype = 10;
if ($row['player_id'] == $option_name1 && $row['item_id'] == $itemtype)
{
$updateweapon = mysql_query("UPDATE items SET quantity = quantity + '15' Where player_id = '$option_name1' and item_id = '$itemtype'");
}
else
{
$insertweapon = mysql_query("INSERT into items(player_id,item_id,status)values('$option_name1','$itemtype','unequipped')");
}
}