SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Categories...how to implement

  1. #1
    SitePoint Enthusiast tvspec's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Categories...how to implement

    I'm doing a quick database with some products that fit into about 5 categories. Some products fit into more than 1 category. I'm brand new at MySQL..and I'm not sure what to use...looks like I should either use ENUM or SET.

    So how do I create a field that can have one or more categories chosen?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tvspec
    I'm doing a quick database with some products that fit into about 5 categories. Some products fit into more than 1 category. I'm brand new at MySQL..and I'm not sure what to use...looks like I should either use ENUM or SET.

    So how do I create a field that can have one or more categories chosen?

    why not use a lookup table and join the tables


    productid categorieid
    1 1
    1 2
    2 4
    2 1
    3 4
    4 5
    Last edited by FliKman; Mar 24, 2003 at 17:45.

  3. #3
    SitePoint Enthusiast tvspec's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by FliKman
    why not use a lookup table and join the tables


    productid categorieid
    1 1
    1 2
    2 4
    2 1
    3 4
    4 5

    Not sure what you mean by "lookup table" currently I had a product id column which has a different number for each product (primary/unique) - then I have a category column (categories 1-5) how would I make it so that some have more than one category without making new rows?

  4. #4
    SitePoint Addict suzkaw's Avatar
    Join Date
    Apr 2002
    Location
    North Carolina
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What he is saying is create a new table that is basically just a look up table. Attached is an example.
    Attached Images
    Thanks Eric.

  5. #5
    SitePoint Enthusiast tvspec's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by suzkaw
    What he is saying is create a new table that is basically just a look up table. Attached is an example.
    I do have a lookup table, but still, the way I have it, using varchar, I can't post two numbers for the two categories that there are for one of the items.

Bookmarks

Posting Permissions

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