MyBB Community Forums

Full Version: PHP/MySQL question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm starting to learn a little bit of php(php7) and MySQLi.

To start with, I'm making a "browser game" that only use buttons, images and that kind of things (something easy).

I don't know if I'm thinking the table structure right... that's my main issue.

An example:

You have your account and you can create a character. The character has several options, like strenght, dexterity, intelligence, etc.

Also, you have a bag with limited slots that you can upgrade in the future, buying a bigger bag.

I want to use different tables for different things, in this case, 3 different bags: the basic (small), the medium and the big one.

So, using this bag as an example...

¿How you link this different bags with your character?

My thoughts were something like using a NUMBER for each one and then, compare with the DB.

¿Am I right or that's not correct?

Thanks for reading.
This isn't PHP or MySQL; its logic.

My favourite way to do things is unique IDs per item

So, ID 1 would be the small bag, 2 the medium, 3 the large. The user has one bag, corresponding to that ID stored in the users table. References to either hard-coded variables in an array() or in its own table in the database.
(2016-08-28, 01:06 AM)Ben Cousins Wrote: [ -> ]This isn't PHP or MySQL; its logic.  

My favourite way to do things is unique IDs per item

So, ID 1 would be the small bag, 2 the medium, 3 the large. The user has one bag, corresponding to that ID stored in the users table. References to either hard-coded variables in an array() or in its own table in the database.

Yeah, I know but it's related for this.

Anyway my thoughs were right, specify unique ids or any kind of data to compare after and tell the user "you bave the small/medium/big bag".

Thanks for your answer Ben Cousins.
The other option is to have a "pivot table." In this case you'd have:

users table
id
any other attributes

items table
id
any other attributes

item_user
item_id
user_id

Then, to get a user's items, you can SELECT WHERE user_id = userID;.
(2016-08-28, 03:40 PM)Josh H. Wrote: [ -> ]The other option is to have a "pivot table." In this case you'd have:

users table
   id
   any other attributes

items table
   id
   any other attributes

item_user
   item_id
   user_id

Then, to get a user's items, you can SELECT WHERE user_id = userID;.

Oh, well... seems like I misunderstood what Ben sayed before.

Yeah I was thinking to use unique identifiers in each table to have a reference after to compare with the rest of the tables, and then make something like that.

Thanks Josh H.