31.05.2014, 14:42
Hi, I've a problem with my inventory saving system.
Even if the item already exist in the database, it goes for an INSERT query, so i've got 2 time the same item.
Thanks in advance.
pawn Код:
stock SavePlayerInventory(playerid) {
new id = PlayerInfo[playerid][pID];
new query[256], temp;
for(new i = 0; i < MAX_ITEM; ++i)
{
if(PlayerInv[playerid][i] > 0) {
mysql_format(DB,query,sizeof(query), "SELECT * FROM `playerinventory` WHERE pid = '%d' AND item = '%d'", id, i);
mysql_tquery(DB,query);
printf("%s", query);
new nbRow = cache_num_rows();
if(nbRow > 0) {
temp = cache_get_field_content_int(0, "amount");
if(temp != PlayerInv[playerid][i]) {
mysql_format(DB,query,sizeof(query), "UPDATE FROM `playerinventory` SET amount = '%d' WHERE pid = '%d' AND item = '%d'",PlayerInv[playerid][i], id, i);
mysql_tquery(DB,query);
printf("%s", query);
}
} else {
mysql_format(DB, query, sizeof(query), "INSERT INTO `playerinventory` (pid,item,amount) VALUES (\'%d\', \'%d\' , \'%d\')", id, i, PlayerInv[playerid][i]);
mysql_tquery(DB, query);
printf("%s", query);
}
}
}
return 1;
}
Thanks in advance.