Jump to content

Recommended Posts

I'm currently building an online text game in PHP and need to create an inventory system.  My thought was that there would be a main inventory database and that players would have 1 inventory field w/ items seperated by a '-' so that later I could explode it and put it into an array and get the items from the database.  I dont know if this is the best idea, so if you have suggestions cool.  My real question however is this: If I wanted to see how many of a certain item were in peoples inventory, how would the SQL for that look? Or would it work? 
Example: I need to see item #44543 so I 'SELECT * FROM users WHERE inventory LIKE '#44543' or would that return false positives?

Any suggestions appreciated.
Link to comment
https://forums.phpfreaks.com/topic/14873-inventory-system-sql/
Share on other sites

Okay, firstly DONT seperate items by - marks. If you were even going to try to store stuff in a database like that, use serialize() (it stores arrays in text format, which you can unserialize() later)--but that's not a good idea either...far too messy IMO.

Actually, I'm going to be working on an inventory system too, for my own RPG (it's based on Harry Potter) so if you want I could definately help you out. I'm going to be making shops and a bank and such...
Link to comment
https://forums.phpfreaks.com/topic/14873-inventory-system-sql/#findComment-59558
Share on other sites

depending on how advanced you would like to make it, you could also make a table like: user, item_id, duribility, creator ...etc This will allow you to make an item "break" or remember where the user got it, and allows for a query to find how many items are in the db that correspond to that user. Just an idea, as it does involve a more complex scheme.

-Kalivos
Link to comment
https://forums.phpfreaks.com/topic/14873-inventory-system-sql/#findComment-59559
Share on other sites

[quote author=ChaosXero link=topic=100913.msg398838#msg398838 date=1153161081]
Wouldn't that evetually create a massive database though?
For example: 1,000 users w/ 1,000 items = 1million rows.  OUCH that hurts.
[/quote]
Would you SERIOUSLY let your users each keep 1,000 items? There HAS to be a limit somewhere.

What I would do is create and items table with all the items information: rarity, value, store, descpription, imagelink, etc. and then a table called inventory with userid as one column and item ID in another. So yea, you'd have a lot but you wouldn't have to put in NEARLY as much information.
Link to comment
https://forums.phpfreaks.com/topic/14873-inventory-system-sql/#findComment-59575
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.