SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Categories?

    I want to be able to add something into multiple categories.

    Currently, when I add something to the database, I choose a category, for example: "Red" with the ID of 1

    That item then belongs to the Red category.

    I have a category page which selects everything for category 1 "Red".

    All red items are displayed on page.

    What I want to know is, how to do multiple categories?

    What if an item is Red and Blue?

    Category 1 - Red and Category 2 - Blue

    How do I insert it into the database to be 1,2 and how do I select that item as just 1 for the Red category but then it is also in the Blue category when you look there?

    Thanks!

    Hope my example was okay
    :-)

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could have a separate table called "prodCats" which has a 1 to many relationship with your "products" table. prodCats would have a record for each product and the categories it is in. You could have foregn keys in prodCats to make sure that the prodId and catId exists in your "products" and "categories" tables.

  3. #3
    SitePoint Enthusiast PHP_Adam's Avatar
    Join Date
    Jan 2009
    Location
    West Yorkshire, UK
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need Three tables.

    categories

    cat_id
    cat_name
    cat_nameseo

    products
    prod_id
    prod_name
    prod_nameseo
    prod_desc

    prod_cat
    cat_id
    prod_id

    The prod_cat table will allow you to list the product id many times to different categories. Hope this helps (Same Advice as Kalon)

    <snip/>
    Last edited by ScallioXTX; Sep 19, 2010 at 17:19. Reason: Removed self promotional link


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
  •