Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Unanswered: User in multiple categories

    I'm building a site that has a section with a directory listing of people that can be viewed by category. When people register, I want them to be able to check ALL categories that apply, not simply choose one or a fixed amount.

    In my database, I have a Categories table that has a CategoryID field as the primary key, and a CategoryName varchar field.

    What's the best way to associate a user with a variable and unlimited number of categories? I want to be able to send a query to the database that returns all the users that are in a particular category, regardless of whether they are in other categories also.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    use an intersection table

    the intersection table contains the primary keys of the two referenced tables.. the user and the category (and if relevant other information pertinent to that intersection.. which doesnt' apply here). I'd suggest you use the PK fo the user and categories table as a composite PK in the intersection table, so one user can only have one instance of a specific category.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Thank you, that's exactly what I needed. Google provided me with a lot of examples, I just didn't know what I needed was called.

Posting Permissions

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