www.webdeveloper.com
Results 1 to 5 of 5

Thread: People experienced with php + database work - advice needed

  1. #1
    Join Date
    Jun 2008
    Posts
    37

    People experienced with php + database work - advice needed

    Hey guys

    I am planning on creating a database that's primarily messages exchanged b/w one person and another. what's the best way to set this up in the long run.

    What I have:
    3 separate tables:
    A table = list of group A people
    B table = list of group B people
    C table = messages b/w A and B

    C table
    messageid | aperson | bperson | time | message


    i'm guessing this isn't how facebook does it?
    And this seems VERY basic... what am i missing or how can i improve this?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    Any particular reason the people need to be split between 2 tables? If the data for each type of person is the same, I would just have one table to which you could add a column to specify if they are type A or B.

    And there's nothing wrong with "basic" if it gets the job done. In fact, "basic" is often better than "complex".
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    Why two tables for users? I'd have the following:

    users:
    id, name, etc

    messages
    id, message, etc

    users_messages
    user_id, message_id

    This will give you a good structure to use within your code, plus the flexibility of conversations not limited to two people. If this is definitely never going to be a requirement you could drop the join table and add the user's ids as foreign keys in the messages table.

  4. #4
    Join Date
    Jun 2008
    Posts
    37
    mm i guess two tables isn't really needed.. its just table a users will never interact with each other and table b users will never interact with each other. there will only be cross interaction. does that make a difference?

    i dont know.. maybe im overthinking it..
    besides the users involved, the message, and the time... am i missing anything else that needs to be documented?

    thanks guys for your quick responses!

  5. #5
    Join Date
    Nov 2008
    Posts
    2,477
    Quote Originally Posted by xpiamchris View Post
    mm i guess two tables isn't really needed.. its just table a users will never interact with each other and table b users will never interact with each other. there will only be cross interaction. does that make a difference?
    No, a user is a user regardless of how they may interact within your system. That kind of logic is best handled by the PHP side. The database is really there just as a repository for data (although relationships between different 'entities' like users and messages obviously needs to be considered at the database level).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles