Categories, subcategories and posts relationship

Discussion in 'Databases' started by xp_vista007, Dec 14, 2013.

  1. #1
    Hi, i am creating a web app with php and mysql.
    My problem is to this three tables: categories, subcategories and posts:
    Category has many subcategories, subcategory belongs to one category,
    category has many posts, post belongs to only one category
    subcategory belongs to one category, post belongs to one subcategory

    I have attached schema of all three tables , so my question is:
    How can I insert a post just in specified category (not in subcategory) ?

    Thnx.
     

    Attached Files:

    xp_vista007, Dec 14, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    With the table-setup you show us, you can't. Simply because under the post-table, you do not directly connect to the main category table (you connect to a subcategory, which THEN connects to the main category table).
    You will have to remake the tables a bit for what you're asking to work.
     
    PoPSiCLe, Dec 16, 2013 IP