If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > User in multiple categories

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-10, 18:10
RyanGiglio RyanGiglio is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 02-06-10, 19:13
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 02-06-10, 19:31
RyanGiglio RyanGiglio is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On