Current location: Hot Scripts Forums » Programming Languages » PHP » Search Engine


Search Engine

Reply
  #1 (permalink)  
Old 07-24-05, 12:25 AM
SummerL SummerL is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Search Engine

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 <= '----'
Code:
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))
{

Last edited by SummerL; 07-24-05 at 12:34 AM.
Reply With Quote
  #2 (permalink)  
Old 07-24-05, 01:07 AM
SummerL SummerL is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #3 (permalink)  
Old 07-24-05, 01:12 AM
SummerL SummerL is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
I have resolved it ..

$beginDate = '';
if(!empty($day) && !empty($month) && !empty($year)) {
$beginDate = $year . '-' . $month . '-' . $day;
}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
User agent question gneeko ASP 1 04-15-05 04:29 AM
Free Search Engine Optimization Tools NameWolf General Advertisements 0 03-31-05 06:44 PM
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 12:38 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.