I'm trying to find the best way to make "filtering" of my data. Filters are set by input fields on front end, and based on that filters (inputs) i need to build query in PHP and retrieve data from MySQL database.
This would be easy if i had only one page and one query where i filter data, but i have more pages which pull data from everywhere around database.
What i have in my mind is to build front end HTML forms, with inputs corresponding to database fields, and then when i get form posted, to go via
if(some_field != '')
$q .= ' AND some_field = some_field_value';
problem is i have some fields which should be compared with LIKE and it only gets more complex introducing more fields and values..
I'm sure that there must be better approach to this problem.
I wonder, is there any good example of best practise to similar data filtering?
What I understand is that you have different pages that you want your backend to cater to? And that some of these pages have similar fields but possible to have two pages with different need of query statement(= vs LIKE)? You may include a hidden field that you check in the php code if it needs to use the query statement with LIKE. It will really be complex since you are trying to cater to varying situations and filter fields.
What I did to my filtering is tackle it one filter for each entity...so for example, I have customer module, it has different filter to Purchase Order module...