I having trouble with my optional search engine..
I'm trying to do a search engine with few drop down boxes as well as some other textfield search..
But the thing is.. whenever i do a search on any other fields.. the date Of Occurence query is sent together as well.. even if the DateOfOccurence isn't selected..
It is to say when i search on AircraftType .. the date of occurence is being searched together with AircraftType.. Even if i didn't select any fields and click search.. it does a search on dateOfOccurence too..
echo $queryAircraftDisplay;
SELECT * from report where reportID != 0 and DateOfOccurence >= '----' and DateOfOccurence <= '----'
It seems like the problem is coming from the $beginDate..
$queryAircraftDisplay = "SELECT * from report where reportID != 0";
if (!empty($_GET['AircraftType']))
{
$queryAircraftDisplay .= " and aircraftType='".$_GET['AircraftType']."' ";
}
if (!empty($_GET['ServicingType']))
{
$queryAircraftDisplay .= " and servicingType='".$_GET['ServicingType']."' ";
}
if (!empty($_GET['YearOfOccurence']))
{
$queryAircraftDisplay .= " and DateOfOccurence ='".$_GET['YearOfOccurence']."' ";
} if (!empty($beginDate))
{
$queryAircraftDisplay .= " and DateOfOccurence >= '$beginDate' and DateOfOccurence <= '$endDate'";
}
if (!empty($_GET['Keyword']))
{
$queryAircraftDisplay .= " and reportID in ($newarr)";
}
echo $queryAircraftDisplay;
$resultAircraftDisplay = mysql_query($queryAircraftDisplay) or die ("couldn't execute query ".mysql_error());
while ($row = mysql_fetch_array($resultAircraftDisplay))
{
It realize it is
$beginDate = $day . "-" . $month . "-" . $year;
that is causing the error
$beginDate will always be "not empty" because the "-" characters will be there at least.
What should i do to not build up $beginDate unless $day, $month and $year are valid.