WEB How would you...

Discussion in 'OT Technology' started by hurleyint1386, Aug 23, 2009.

  1. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    So lets say you've got a database of users and groups. You want to have what groups the user is in and they are not exclusive to just one group. If you have a group ID in both tables, then you could join them, however, if the person is in multiple groups, then if I separate the group IDs by a comma, then it would be a varchar instead of an int, then I would probably have to splice the whole thing. Would that be how you do it? Or is there a better way?
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    oh god, don't comma delimit the ids

    you want another table to represent the user's group membership.

    i.e.

    User
    UserId
    Name
    etc

    Group
    GoupId
    Name
    etc

    GroupMembership
    GroupMembershipId (primary key, auto incr.)
    UserId
    GroupId
     
  3. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    Hmmm, that's true. So I could use select * where groupid = X. Although would I need to join it with both tables? I remember joining 3 tables, and it definitely wasn't fun haha. But it definitely makes more sense to do it that way,. Thanks
     
  4. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    Nevermind, I got it quicker than I thought I would haha
     

Share This Page