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 3450748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:04:50+00:00 2026-05-18T09:04:50+00:00

Im trying make a menu with the next structure: -category 1 –category 1.1 —category

  • 0

Im trying make a menu with the next structure:

-category 1
--category 1.1
---category 1.1.1
----product 1
----product 2
----product 3
-category 2
--category 2.1
---category 2.1.1
----product 1
----product 2
----product 3
-category 3
--category 3.1
---category 3.1.1
----product 1

I have an scheme like wordpress:

relation_category_products table store an id from category and id from products.
The question is whats the best way to make the mysql queries for having all that structure?
My first solution it was make queries for parent category (-category), then for each every row take the id for the next –category and then until raise the product node. But with that tecnique theres a lot of queries (35 for the moment). And i dont know whats the better way to get all that relationship and take it with php for render the menu.

thanks

  • 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. Editorial Team
    Editorial Team
    2026-05-18T09:04:50+00:00Added an answer on May 18, 2026 at 9:04 am

    http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

    Your table structure should have a field for the parent, e.g.

    Table “category”

    id(int)  name            parent(int)
       1     Category 1 
       2     Category 1.1     1
       3     Category 1.1.1   2
       4     Category 2       
       5     Category 2.1     4
    

    You then use a one-to-many relationship in your “Product” table to link them to a category.

    If you want to retrieve the nodes directly under a category, just SELECT by the “parent” field.

    If you want to retrieve the whole tree use a join query:

    SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3
    FROM category AS t1
    LEFT JOIN category AS t2 ON t2.parent = t1.id
    LEFT JOIN category AS t3 ON t3.parent = t2.id
    

    This will give you back something like:

    +-------------+----------------------+---------------+
    | lev1        | lev2                 | lev3          |
    +-------------+----------------------+---------------+
    | Category 1  | Category 1.1         | Category 1.1.1|
    | Category 2  | Category 2.1         | NULL          |
    +-------------+----------------------+---------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Generally I have MenuItems model and trying to make '/menu_items(/:id(:/some_action))' URLs looks like '/menu(/:id(:/some_action))'
I have been trying to make the sub-menu horizontal. In my HTML it looks
i'm trying to make a menu, i want my menu looks like centered to
I'm trying to make my menu appear from the right of the screen like
I am trying to make a basic java console based menu system. I have
I'm trying to make an Android layout like the one below. I have a
I'm trying to make a jQuery dropdown (more like drop right!) menu. What I
I have a component called X. I'm trying to make a menu come down
I am trying to make a menu using checkboxes, which i have created programmatically.
I'm trying to make dynamic menu using xml data, I'm creating that menu using

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.