Processing multiple WHERE clauses for search

sql

#1

I am developing search functionality as part of a project, the search needs to be fairly advanced with a lot of options for the user to search on.

My data is stored in a MySQL table, there are several tables that I am querying using LEFT JOIN etc. I am fairly comfortable constructing these MySQL queries and have several already working to serve content on various pages already.

My search is a set of fields (mainly select fields and checkboxes), when a user clicks the search button I’d like to append all of the values of the fields they select to a URL as variables and pass them through to a PHP script that takes those values and generates the various WHERE OR AND clauses.

It’s clear that if elseif statements are the way to go, but I’m not sure how to incorporate the SQL query in PHP in a way that the SQL clauses can be set in this way.

At present, I can deal with only one variable at a time.

I think I’m ok with the form side of things but how would I construct a query that works in this way with multiple variables?


#2

#3