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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:49:28+00:00 2026-05-28T00:49:28+00:00

Using mysql (and php) I try to hide out of a select menu category’s

  • 0

Using mysql (and php) I try to hide out of a select menu
category’s that are not available for the item selection.
Basically I’m stuck and can’t thing of a way to do it.

Asos uses this technique to browse trough there products ( http://www.asos.com/Men/Jeans/Cat/pgecategory.aspx?cid=4208 ).

To be clear the problem is not how to do the ajax stuff but how efficiently use mysql and php to make a system like this.

I’ve tried to figure out to do this with nested sets:

    (1)items(22)----------------------------------
          |                           |
          |                           |
    (2)producs(7)                  (8)origin(21)
          |                           |
(3)single(4)-(5)bundle(6)             |
                             ---------------------
                             |                   |
                            (9)EU(14 )        (15)ASIA(20)   
                             |                   |   
                          ----------------      -----------------
                          |             |         |              |
                        (10)DU(11)  (12)PL(13)  (16)CN(17)   (18)JP(19)

Menu:
type:
-single
-bundle

origin:
-EU
-ASIA

country:
-DU
-PL
-CN
-JP

Lets say there’s one item in the db:
item ‘1’ is in:
-single
-EU
-DU

Item category table:

itemID - cat_lft - cat_rgt
  1        10        11
  1        7         12
  1        2         3

In the menu selecting DU should select:
DU-EU-SINGLE

And deselected the rest (return a array?) because theres is only one item for now.

You could get the items and compare if the result are present in the remaining category’s, but that sounds like using a lot of query’s…

Any advice where to go from here?

  • 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-28T00:49:29+00:00Added an answer on May 28, 2026 at 12:49 am

    Here’s how I would do it. Make sure your products are categorized with leaves only (i.e. left = right + 1). So, a product can be categorized as “DU,” but not “origin” or “ASIA.”

    Category table:

    • category_id
    • name
    • left
    • right

    Products table:

    • product_id
    • name
    • …

    Categories_Products table:

    • category_id
    • product_id

    SQL query to determine checked vs. unchecked categories:

    SELECT
        `categories`.`category_id`,
        `categories`.`name`,
        IFNULL(COUNT(`categories_products`.`id`), 0) AS `count` FROM `categories`
    
    LEFT JOIN `categories` as `children` ON
        `children`.`left`  > `categories`.`left`  AND
        `children`.`right` < `categories`.`right`
    
    JOIN `categories_products` ON
        `categories_products`.`category_id` = `children`.`category_id`
    
    GROUP BY `categories`.`category_id`
    

    If “count” is 0, leave it unchecked; otherwise, it’s checked, and you know how many items are in that category. This is untested, so it might need some tweaking. You DEFINITELY want indexes on category_id, product_id, left, and right columns.

    Addition: SQL query to select products in one or more categories (see below for compound conditions):

    SELECT `products`.* FROM `categories`
    
    JOIN `categories` as `children` ON
        `children`.`left`  >= `categories`.`left`  AND
        `children`.`right` <= `categories`.`right`
    
    JOIN `categories_products` ON
        `categories_products`.`category_id` = `children`.`category_id`
    
    JOIN `products` ON
        `products`.`product_id` = `categories_products`.`product_id`
    
    WHERE `categories`.`category_id` IN (1,2,3,n,...)
    
    GROUP BY `products`.`product_id`
    

    Addition: Logic to select products in multiple categories, compound filtered (product must be in all categories to be a match):

    You’ll have to do separate joins for every category requirement you want. Please note that this type of query could get pretty slow, so do some benchmarking as you go. You might be better off with multiple queries (one for each category), combining the results in the application code.

    Along those same lines, I’d recommend that something like “single vs. bundle” be an ENUM in your products table, and categorization is left to more abstract structures (region works, and so would a traditional consumer-facing, “logical” categorization structure) that aren’t a simple either/or flag.

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

Sidebar

Related Questions

(Using MySQL and PHP) I have a search form that will allow my users
I am using MYSQL and PHP. I have a table called item. Two of
I am trying to connection with php-MySQL using below code try{ HttpClient httpclient =
I'm using php and mysql. When i try to export the database using phpMyAdmin.
I am using MySQL and PHP for a project I am working. I have
I am using MySQL and PHP to build a data layer for a flash
I'm using MySQL with PHP. This is like my table: (I'm using 3 values,
Been using PHP/MySQL for a little while now, and I'm wondering if there are
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I'm building a wepage in php using MySQL as my database. Which way is

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.