Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 90047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:48:44+00:00 2026-05-10T22:48:44+00:00

I’m making list of items in categories, problem is that item can be in

  • 0

I’m making list of items in categories, problem is that item can be in multiple categories. What is your best practice to store items in categories and how list all items within category and its child categories? I am using Zend Framework and MySQL to solve this issue.

Thanks for your replies.

Sorry for my English 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:48:44+00:00Added an answer on May 10, 2026 at 10:48 pm

    So, you have a hierarchy in the categories, yes? Is it one level (category and child category) or any number (children can have children, etc)? That will impact what the solution is.

    Generally, you’d model something like this with a many-to-many relationship, like:

    CREATE TABLE Item(   item_id INT NOT NULL,    item_name VARCHAR(255) NOT NULL ) CREATE TABLE Category(   category_id INT NOT NULL,    category_name VARCHAR(255) NOT NULL ) CREATE TABLE Item_Category(   item_id INT NOT NULL REFERENCES Item(item_id),    category_id INT NOT NULL REFERENCES Category(category_id)  ) 

    A record in ‘Item_Category’ means that the listed item is in the listed category. You can then do joins between 2 (or 3) of those tables to list which items are in which categories:

    SELECT I.*    FROM Item I      INNER JOIN Item_Category IC ON I.item_id = IC.item_id      INNER JOIN Category C on IC.category_id = C.category_id    WHERE      C.category_name = 'MyCategory' 

    Or which categories an item has:

    SELECT C.*   FROM Category C     INNER JOIN Item_Category IC.category_id = C.category_id      INNER JOIN Item I on IC.item_id = I.item_id   WHERE      I.item_name = 'MyItem' 

    If there’s a hierarchy in the categories, that could be expressed using a recursive relationship in the category table, such as:

    CREATE TABLE Category(   category_id INT NOT NULL,    category_name VARCHAR(255) NOT NULL,   parent_category_id INT NOT NULL REFERENCES Category(category_id) ) 

    That makes things more complicated because you have to use recursive queries to get all the records for a category and its children. A simpler way, if you have only two levels of categories, it to simply make it a second field on the category table, like:

    CREATE TABLE Category(   category_id INT NOT NULL,    category_name VARCHAR(255) NOT NULL,   subcategory_name VARCHAR(255) NULL ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.