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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:55:02+00:00 2026-05-22T21:55:02+00:00

I am trying to set up a filter system for a small shop I

  • 0

I am trying to set up a filter system for a small shop I am developing. Basically, I am working the results off a list of variables. the page, products.php if there is no querystring will show all products. However, if there is a variable present I want it to alter the select statement where necessary.

however, I am having problems filtering. If i use the AND statement for all variables it does not filter appropriately neither does the OR. So if i wanted black size 5 shoes it would show all size fives regardless of color.

Is there a better approach to take with this as is becoming a fair old head scratcher!

if ($queryString == NULL){
    $query = "SELECT * FROM store_products 
JOIN store_cat on store_products.cat=store_cat.cat_id 
JOIN prod_sizes on store_products.prod_id=prod_sizes.product_id
JOIN prod_color on store_products.prod_id=prod_color.product_id 
GROUP BY store_products.prod_id";   
}else{
        $query = "SELECT * FROM store_products 
JOIN store_cat on store_products.cat=store_cat.cat_id 
JOIN prod_sizes on store_products.prod_id=prod_sizes.product_id
JOIN prod_color on store_products.prod_id=prod_color.product_id 
where store_products.sale='$sale' OR prod_color.color='$color' OR prod_sizes.size='$size' OR store_products.cat='$cat' GROUP BY store_products.prod_id";
}

example variable string

products.php?sale=&cat_id=1&size=&color=Yellow
  • 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-22T21:55:03+00:00Added an answer on May 22, 2026 at 9:55 pm

    Try building your WHERE criteria before running the query.

    String:
    products.php?sale=&cat_id=1&size=&color=Yellow

    myfile.php

    $criteria = "WHERE 1 ";
    
    if (isset($_GET['sale']) {
        $criteria .= "AND tore_products.sale=$_GET['sale'] ";
    }
    if (isset($_GET['cat_id']) {
        $criteria .= "AND store_products.cat=$_GET['cat_id'] ";
    }
    if (isset($_GET['color']) {
        $criteria .= "AND tore_products.color=$_GET['color'] ";
    }
    

    And so on then run your query:

    $query = "SELECT * FROM store_products 
    JOIN store_cat on store_products.cat=store_cat.cat_id 
    JOIN prod_sizes on store_products.prod_id=prod_sizes.product_id
    JOIN prod_color on store_products.prod_id=prod_color.product_id
    $criteria
    GROUP BY store_products.prod_id";
    

    And please remember to clean your $_GET variables prior to querying with them using mysql_real_escape_string, mysqli or PDO!

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

Sidebar

Related Questions

I'm trying to set up a filter query in one of my views...basically my
I was trying use a set of filter functions to run the appropriate routine,
im trying to set the height of two divs on my page, because my
I'm trying to filter a set of records based on a sub-object's criteria. This
I'm developing a tax calculation system that applies various taxes based on a set
I am trying to build a simple jQuery filter system to show and hide
I'm trying to set up a filter using jQuery. I'll have a certain amount
I am trying to set windows desktop search to use a different html filter
Im trying set the single table inheritance model type in a form. So i
I am trying set up databinding as described in the title. The problem I

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.