hello,
I am trying to perform a query where the user can search for:
Exams Passed / Failed / Both
Date search between 2 dates, or leave the dates blank.
I have made this large if statement to try and make the "WHERE" clause for my queries depending on what the user entered.
basically it ignores the dates altogether if the user does not enter a full date (if they leave one day or month out etc)
If the dates are ok then it searches for passes/fails or both.
Now if the dates are not entered, then its only bringing out Passes regardless of what the "passed" variable is.
And if the dates are entered its bringing out passes and fails regardless of what the "passed" variable is.
Anyone know what im missing pleasE?
if($_POST['year1'] == "" || $_POST['month1'] == "" || $_POST['day1'] == "" || $_POST['year2'] == ""
|| $_POST['month2'] == "" || $_POST['day2'] =="" && $_POST['passed'] =="passes")
{
$where = "WHERE percent >= '75'";
}
elseif($_POST['year1'] == "" || $_POST['month1'] == "" || $_POST['day1'] == "" || $_POST['year2'] == ""
|| $_POST['month2'] == "" || $_POST['day2'] =="" && $_POST['passed'] =="fails")
{
$where = "WHERE percent <= '74'";
}
elseif($_POST['year1'] == "" || $_POST['month1'] == "" || $_POST['day1'] == "" || $_POST['year2'] == ""
|| $_POST['month2'] == "" || $_POST['day2'] =="" && $_POST['passed'] =="both")
{
$where = "";
}
elseif($_POST['passed'] == "passes")
{
$where = "WHERE percent >= '75' AND date BETWEEN '".$date1."' AND '".$date2."'";
}
elseif($_POST['passed'] == "fails")
{
$where = "WHERE percent <= '74' AND date BETWEEN '".$date1."' AND '".$date2."'";
}
elseif($_POST['passed'] == "both")
{
$where = "WHERE date BETWEEN '".$date1."' AND '".$date2."'";
}