Dear experts!

You need to organize advanced output filtering from MySQL. It is interesting to me where to start, what you need to know and how to develop it correctly, so that in the future you can easily add other filtering parameters and, accordingly, do not load the database.

In the picture that I attached below, you can see the type of filtering, as I want to do.

Please tell me if there are any special frameworks, or explain the PHP algorithm for developing data filtering.

Thank!

enter image description here

  • what is the question? How dynamically request to form with where ? - pavel
  • @pavel, The question is: where do I start, explain the data filtering algorithm, because I do not know anything about filtering. - Maqsood
  • yes what's the algorithm there. Stupidly drive a SQL query. Tipo Select .... where ... = ... and ... = ... I think it’s easy to substitute the parameters. - pavel
  • @pavel, for example, how to display all the available parameters for filtering? how to organize it all. I have enough algorithm in PHP. DB Mysql. - Maqsood
  • No algorithm is needed, just make a form in HTML - Ipatyev

2 answers 2

First you need to decide on the data storage scheme.

You need the following tables:

  1. Properties (property) - categories for filtering are stored in it (id, property_name)
  2. Property values ​​(property_value) - property values ​​are stored in the table (id, value, property_id)
  3. Table with goods - goods are stored in the table with reference to the property_2_product table
  4. Table property_2_product - property binding to goods is stored in the table (id, product_id, property_value_id)

To build a filter, you need to select values ​​from the first two tables. To display the results, you need to select data from tables 3 and 4, taking into account filtering.

PHP algorithm is simple.

To display the filter:

  1. Select filter categories and filter values
  2. In the loop we display data

To filter products:

  1. The filter is an HTML form - the results fall into PHP.
  2. In PHP, we get filtering options.
  3. Choose products by parameters from the table of goods
  • Opened my eyes! Now I understand which way to go. Thank you very much! - Maqsood

There are two ways

1 - Write a "vertical take-off combine" that will parse the XML config with an abstract description of various filters

Pros:

  • Easy to add new filters.

Minuses:

  • Inadequate task complexity of development and development
  • Performance drawdown
  • The difficulty of finding the point of failure
  • The understanding that arose two years later that you need to add a filter that does not fit into the circuit. Crutches, popabol and other pleasures of life
  • The understanding that arose in three years that for all these three years only one filter was added, and that from the previous paragraph

2 - Do not engage in nonsense and zhardkodit filters you currently need (following the rules of a good code essno)

Pros:

  • Ease of development and development
  • Taki speed
  • Easy to find point of failure

Minuses:

  • Well, yes, to add a new filter will require revision.