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 <= '----'
function DateofOccurence()
{
$day = array (1=>"-","01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");
$select = "<select name=\"day\">\n";
foreach ($day as $key => $val)
{
$select .= "\t<option val=\"".$key."\"";
if ($key == 1)
{
$select .= " selected>".$val."\n";
}
else
{
$select .= ">".$val."\n";
}
}
$select .= "</select>";
echo $select;
$month = array (1=>"-","01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
$select = "<select name=\"month\">\n";
foreach ($month as $key => $val)
{
$select .= "\t<option val=\"".$key."\"";
if ($key == 1)
{
$select .= " selected>".$val."\n";
}
else
{
$select .= ">".$val."\n";
}
}
$select .= "</select>";
echo $select;
$year = date("Y"); //get the year from $today
echo "<select name='year'>\n";
echo '<option value="" selected">-</option>';
for ($n=$year;$year-10<=$n;$n--)
{
echo " <option value=\"$n\">$n</option>";
}
echo "</select>\n";
}
$day = isset($_REQUEST['day']) ? $_REQUEST['day'] : '';
$month = isset($_REQUEST['month']) ? $_REQUEST['month'] : '';
$year = isset($_REQUEST['year']) ? $_REQUEST['year'] : '';
$beginDate = $day . "-" . $month . "-" . $year;
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))
{