2

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. :)

3
  • 3
    Is doing an n-to-m relation out of the question? Or actually, 1-to-n might suffice, seeing that one player can only be in one mob, right? That way, you could make the database do the heavy lifting for you. Commented Nov 20, 2012 at 8:22
  • @Grüse: It appears to me that, far from "one player only being in one mob", PlayerId 134 above is in five mobs. Commented Nov 20, 2012 at 8:50
  • @eggyal: You're right, I seem to have misunderstood the concept of a Mafia mob membership and its seemingly non-exclusive nature ;) Commented Nov 20, 2012 at 16:57

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly, or - if a player can only be in one mob at any given time - you could add a "MobId" column in your Player table that saves this player's mob allegiance.
0

You can try

 CREATE TABLE PlayerMobs (
 PlayerId INT UNSIGNED NOT NULL,
 MobId   Text UNSIGNED NOT NULL);

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.