#1

PHP код:
SaveInventory(playerid)
{
    new 
_query[73];
    
    
mysql_format(handle_querysizeof(_query), "DELETE FROM `Inventory` WHERE `PlayerID` = %d"pInfo[playerid][pID]);
    
mysql_tquery(handle_query);
    for(new 
ii<pInventory[playerid][iUsedSlots]; i++)
    {
        if(
pInventory[playerid][iItemAmount][i] > 0)
        {
            
mysql_format(handle_querysizeof(_query), "INSERT INTO `Inventory` VALUES (%d, %d, %d)"pInfo[playerid][pID], pInventory[playerid][iItems][i], pInventory[playerid][iItemAmount][i]);
            
mysql_tquery(handle_query);
        }
    }
    
    return 
1;

This is code for the player inventory. Once the player pick up an item it will save in this database: http://prntscr.com/jwphpc

As you can see, it makes another line, same id and the new item.

I wanted to change it work into this new database which have "PlayerId>Inv_1,_inv_2..., and so on up to Inv_50.

I want to change this query so every item the user picks up it will save to the next slot. Example a user pick up an item, it will save on "Inv_1", but if he picks up another item(doesn't matter if its the same or not) it should same to the next slot which is "Inv_2".

How do I do that? Thanks.
Reply
#2

The database structure you are describing has many flows:
• 50 unused columns
• duplicates

Try to maintain 15-20 columns per table and not more.
Having the same item multiple times when can be combined into one is not good either.

The ideal database structure would be like the current one: <userid>, <itemid>, <amount>
But instead of sending a DELETE query and multiple INSERT, combine them.

A player can have an item only once so <userid>, <itemid> is a UNIQUE constraint. If set like this, when executing a query such:
pawn Код:
"INSERT INTO Inventory VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE amount=%d;"
It will do either of these:
• Insert a new record if it does not exist.
• Update amount of item for X player and Y item.
Reply
#3

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
The database structure you are describing has many flows:
• 50 unused columns
• duplicates

Try to maintain 15-20 columns per table and not more.
Having the same item multiple times when can be combined into one is not good either.

The ideal database structure would be like the current one: <userid>, <itemid>, <amount>
But instead of sending a DELETE query and multiple INSERT, combine them.

A player can have an item only once so <userid>, <itemid> is a UNIQUE constraint. If set like this, when executing a query such:
pawn Код:
"INSERT INTO Inventory VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE amount=%d;"
It will do either of these:
• Insert a new record if it does not exist.
• Update amount of item for X player and Y item.
We have 55 colums in total and it worked fine before. I just need to re-script the querie for that.(Since we're on a DayZ, and thats the inventory system. But still, thanks for the help I really appreciate that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)