Reputation: 105
Question: Stated in title
Project: My PHP Mafia/Mobsters Strategy Game
Reason for Asking: I'm unsure how I would word this question into a somewhat relevant Google search.
I would like to know which MySql variable type I should use for an array. I will explode this array into an ID list including all people in that players mob.
EXAMPLE MYSQL DATA BELOW:
PlayerId -------- Mob //Lables
134 ------------- '23','59','12','53','801' //Values
This will then be exploded using explode()
in PHP into a bunch of ints containing the IDS of players in that persons mob.
I would like the mob field to have an unlimited character length so that players can have HUGEE mobs.
I think I may be able to simply use longtext
or the set
type but I'm not completely sure. I don't want any errors later on once I release the game and I want my methods to stay clean and correct.
Thank you so much for taking the time to read this, I hope you can help. :)
Upvotes: 2
Views: 102
Reputation: 105
I did this a very long time ago, but I happened to come across the question when browsing through my account.
There aren't any specific "mobs." Your "mob" is basically like a friends list. It's not a group. It's just a bunch of people connected to you.
I believe I simply made a row for "mob members" and just put the other players ids, separated by commas, then in the PHP I exploded the string with a comma as the delimiter.
Upvotes: 0
Reputation: 109
You can try
CREATE TABLE PlayerMobs (
PlayerId INT UNSIGNED NOT NULL,
MobId Text UNSIGNED NOT NULL);
Upvotes: 0
Reputation: 125855
You should create a table that associates players with mobs:
CREATE TABLE PlayerMobs (
PlayerId INT UNSIGNED NOT NULL,
MobId INT UNSIGNED NOT NULL,
FOREIGN KEY (PlayerID) REFERENCES Players (PlayerID),
FOREIGN KEY (MobID) REFERENCES Mobs (MobID)
);
And then join it with your other tables in queries as required.
I have added FOREIGN KEY
constraints to ensure that only valid PlayerID
and MobID
values exist in the PlayerMobs
table, but note that these constraints currently only work with the InnoDB
storage engine.
Upvotes: 5