www.webdeveloper.com
Results 1 to 4 of 4

Thread: Sub Categories...HELP!

  1. #1
    Join Date
    Aug 2006
    Location
    UK
    Posts
    4

    Sub Categories...HELP!

    Hi all!

    Ok, I'm trying to complete a shopping site for a design course. The basic problem is this:

    On my main product page there are a number of product categories, most of which lead to the list of products, but some categories have sub categories, ie: the kitchen category has crockery, cutlery, glassware etc.

    In my database I have a category table and a sub category table but if you click the kitchen link it displays ALL sub categories, which I dont want.

    How do I get it to just display the kitchen sub categories. I'm sure this is so simple but my head wont fit around it.

    Do i need seperate database tables for each sub category?? I'm sure that isn't the answer cos it seems so long winded but its all my brain will answer at the minute - minly because its fried!

    Please help!

  2. #2
    Ubik's Avatar
    Ubik is offline <%= "New Meja Hor" %>
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    SQL:

    Select subcategory.name from maincategory, subcategory where subcategory.maincategorypkey=maincategory.pkey and maincategory.name='kitchen'
    --Ubik

    If I have no idea what you are talking about, then I will pretend I know and answer accordingly.

    Thinking about starting a New Thread entitled 'Please Help Me!' ? Read this!

  3. #3
    Join Date
    Aug 2006
    Location
    UK
    Posts
    4

    Exclamation

    OK, explain this to me like I'm 5 yrs old (I literally have smoke coming from my ears at the moment...) ( Sorry to be a complete numpty )

    My database tables are like this:

    Main categories table: (Categories)
    CategoryID, Category, Pic

    Sub Categories table: (Categories2)
    Category2ID, Category2, Pic2

    So how does your SQL work in that instance. You kinda lost me when there was no inner join mentioned.

    Thanks for your help!

  4. #4
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    i assume there's a bit missing from those tables, you need a foreign key in subcategories don't you? or do you have a link table "between" them?

    the sql ubik has given you does do a join and he has assumed you have a foreign key on the subcategory table.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles