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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:46:54+00:00 2026-05-12T18:46:54+00:00

I am building an EC website for a customer and the project manager came

  • 0

I am building an EC website for a customer and the project manager came with some strange ideas and I am struggling to actually implement what he sold to the client.

Here comes my main issue and a quick summary how the system is setup: product are inside categories, categories could be children of an another category. So the category is presented as a tree on the left sidebar of the website.

The user can browse any category, even non “leaf” category, if the user click on non leaf category a listing like that should be presented for exemple on a level 1 category (same apply to level 2 categories):

big category 1
 category level ( 3 or 2 )
  product 1
  product 2
  product 3
 category level ( 3 or 2 ) 

The things should also have some paging and present on 5 product on each page. Plus the category should be ordered in same fashion they appear in the menu on left side … my DB scheme is like this:

+-------------+    +-------------+
+ category    +    + product     +
+-------------+    +-------------+
+ category_id +    + product_id  +
+ parent_id   +    + category_id + 
+-------------+    +-------------+

I cannot really figure out how I should code the SQL to make sure the product appear in order they should(like ordering product and categories has menu).

Also I am concerned about the performance of the whole setup, if the user select a non “leaf” category I would have to search all the child category and make a big category IN ( id1, id2, id3 ) and I know by experience long IN statement don’t perform well.

If someone have encountered same design/issue and have some advice how to make it I would be grateful.

  • 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-12T18:46:54+00:00Added an answer on May 12, 2026 at 6:46 pm

    You could use the Materialized Path design. A directory path is an example of materialized path. That is, a series of ancestor values, concatenated together, with some character (“/” or “,” are common) separating them.

    So you might have categories:

    +---------------------------------------------+
    | cat_id | Name            | cat_path | depth |
    +---------------------------------------------+
    |    1   | Electronics     | 1/       |   1   |
    |    2   | Digital cameras | 1/2/     |   2   |
    |    3   | SLR cameras     | 1/2/3/   |   3   |
    |    4   | Audio           | 1/4/     |   2   |
    |    5   | Speakers        | 1/4/5/   |   3   |
    |    6   | Wall Satellites | 1/4/5/6/ |   4   |
    |    7   | Computers       | 1/7/     |   2   |
    +---------------------------------------------+
    

    Now if you want all products that are under Audio, you can do a query like:

    SELECT p.*, pc.*
    FROM Products p JOIN Categories pc ON (p.cat_id = pc.cat_id)
    JOIN Categories c ON (pc.cat_path LIKE c.cat_path||'%')
    WHERE c.name = 'Audio';
    

    For example, '1/4/5/6' LIKE '1/4/%' is true, therefore Wall Satellites are included. And same for any other subcategory of Audio.


    Re your question about menu rendering: I assume you’d want the menu to render:
    – All ancestors of the chosen category
    – All siblings of the ancestors of the chosen category

    So if you choose ‘Speakers’, you’d see:

    • Electronics
      • Audio
        • Speakers
      • Computers
      • Digital Cameras

    But you don’t want descendants of Computers or Digital Cameras (i.e. “cousins” of Speakers).

    SELECT uncle.name, uncle.depth
    FROM Categories chosen
    JOIN Categories ancestor ON (chosen.cat_path LIKE ancestor.cat_path||'%')
    JOIN Categories uncle ON (ancestor.depth = uncle.depth
      AND SUBSTRING(REVERSE(ancestor.cat_path), 3, 100) = SUBSTRING(REVERSE(uncle.cat_path), 3, 100))
    WHERE chosen.name = 'Speakers'
    ORDER BY uncle.depth, uncle.name;
    

    I’m using a trick to detect uncles: compare the paths, after stripping the last element. To do this, reverse the string and then strip the first element. This should work at least in MySQL and MS SQL Server, but REVERSE() isn’t standard and might not be portable to other brands of RDBMS.

    Note that you should probably allow for more than one digit for each element in the cat_path, in which case the substring offset should also increase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building some custom content types to capture customer data on a website. Admins
I am building a customer-facing website that requires me to build 1) some analytics
I am building new website in this website client required 24/7 live customer support.
We are building a multi-tenant website in ASP.NET, and we must let each customer
I am just building website for our client. It is simple page which lists
I am building a website for a customer who may not be very computer
I am building a product catalog for a customer website under ASP.NET using .NET
Ok, so I'm building a website that has client profiles. A web user finds
I am building a website to showcase some photos. The photos are viewed using
I would like to make a website where I can present some project of

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.