I've got below snippet where $filter_xx
values are extracted from a dropdown basis user choice.
I'm trying to query the mySQL database with what the user chose to query the database with via dropdown selection.
You will see that there are 4 $filter_xx
variables and how many of them are set in a given instance is completely random.
The issue is when I use &&
in the query it checks if all four parameters are true and then throws and output. (Well I know &&
is suppose to work that way!). I tried replacing all &&
operators with ||
and had no luck.
How do I search the database with only options selected by the user?
if(isset($filter_brand) || isset($filter_year) || isset($filter_month) || isset($filter_status))
{
$query = "SELECT * FROM targets WHERE brand='$filter_brand' && startyear='$filter_year' && startmonth='$filter_month' && status='$filter_status' ORDER BY createdon DESC";
} else {
$query = "SELECT * FROM targets ORDER BY createdon DESC";
}