MySQL problem
#1

Hi, I've a problem with my inventory saving system.

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;
}
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.
Reply


Messages In This Thread
MySQL problem - by PakPak - 31.05.2014, 14:42
Re: MySQL problem - by nmader - 31.05.2014, 14:45
Re: MySQL problem - by PakPak - 31.05.2014, 14:47
Re: MySQL problem - by nmader - 01.06.2014, 05:05
Re: MySQL problem - by DobbysGamertag - 01.06.2014, 05:13
Re: MySQL problem - by Vince - 01.06.2014, 10:55

Forum Jump:


Users browsing this thread: 4 Guest(s)