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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:12:44+00:00 2026-05-29T23:12:44+00:00

Really hope someone can help me or at least point me in the right

  • 0

Really hope someone can help me or at least point me in the right direction. I working on a product site, that allows visitors to filter their results using a menu on side of the product results, similar to what http://www.asos.com have done. Basically, they can chose product type, style,price,fit … etc. Each of these fiter types, have their own table and a reference table which links each value to the products table. EG There is a

Products table with productkey and all other product information
Colours table, with the following fields, Colour_ID, Name
Colourref table with productkey, Colour_ID

I’m using MySQL and PHP. I know how to query the database and display the data if the visitor makes one selection from each filter type and then to display the counts for each attribute, but I’d really like to be able to allow them to make multiple selections and then calculate the counts for each attribute, based on what’s been selected. I’ve looked into how this should be done, and I’ve seen that subqueries are an option, but I’m concerned about how many subqueries I would need to create as I have 9 filter groups, that can have a large number of values. There are currently, 1/2 million products in the database, and this grow over time. I’m capturing the values that need to be queried via the url, so as an example

page=1&view=20&product=125,137,147&type=1,3,5&colour=3,9,5&material=187,345

As you can see from the example, I can have multiple values for each time. I tried writing a query using AND. Example, product = 125 AND product = 137, but that doesn’t work.

Does anyone have any advice on the best way to go about doing this even if it’s just a point in the right direction?

Any help will be greatly appreciated

Thank you in Advance

Vivien

  • 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-29T23:12:45+00:00Added an answer on May 29, 2026 at 11:12 pm

    Basically you answered your own question already:

    SELECT ...
    FROM ...
    WHERE   (product = 125 OR product = 137) AND  
            (colour = 3 OR colour = 8 OR colour = 5) ...
    

    You need to use OR instead of AND if you want to select several products, colours and so on.
    If you want both a product and colour then you need to combine those using AND in between. There is no need for subqueries here.


    It’s easier to use IN though:

    SELECT ...
    FROM ...
    WHERE product IN (125, 137, 147) AND colour IN (3, 5, 8)
    

    A more complete example of this SQL code:

    SELECT p.* 
    FROM Products p
    
    LEFT JOIN Colourref cr
    ON cr.productkey = p.productkey
    
    LEFT JOIN Colours c
    ON c.Colour_ID = cr.Colour_ID
    
    WHERE 
        p.productkey IN (1, 2, 4)
        AND c.Colour_ID IN (1, 2)
    

    This will select all products that have the ID 1, 2 or 4 which have the colours 1 or 2.

    It left joins the required tables on the IDs and then filters the desired values.

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

Sidebar

Related Questions

I'm almost losing it, i really hope someone can help me out! I'm using
I have a really hard time understanding routes and I hope someone can help
Really hope someone can help me as I'm a bit stuck :S I have
I really hope someone can help on this because I'm learning cocoa and have
This is really bugging me, so I hope someone can help me a bit
I'm having a really frustrating problem I hope someone can help me with. Here
I really hope someone can help me with this. Basically i have an issue
I really hope someone can help with this problem. I have an ajax pagination
I really hope someone can help me with this. I'm struggling with it for
I'm driving myself nuts with this particular problem, i really hope someone can help!

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.