I’m making a game in PHP with MySQL and I was wondering what is the best way for me to store the items the users have purchased so it is linked with their account.
I plan to have a database with the items information in and the only ways I could think of doing it was:
- Having a table for the users items in a serialised array of sort
- Having masses of columns with a set amount of inventory space
- Table with user_id and item_id and add a row every time they purchase an item, selecting the user_id relevant to the user to display their items
Which is best?
I think that you know at the beginning which items a user can buy, so in my opinion you should have three tables
PRIMARY KEYis user_id)PRIMARY KEYis item_id)This design lets you easily manage bought items and show every user its inventory.
More: you avoid wasting space in database duplicating unuseful informations