Hello,
I have a basic search engine and I was wondering if it can be done so I don't have to refresh my page, it also has a pagination to it.
This is my form.php
<?php
global $search_term;
global $location_term;
?>
<form action="index2.php" name="form" style="float:right;width:650px;height:60px;margin-right:30px;" onSubmit="return searchLocations();" >
<table style="float:right;"><tr>
<td>
<label for="testinput"><b>Search</b> </label><br />
</td>
<td>
<label for="testinput"><b>Location</b></label><br />
</td></tr>
<tr>
<td>
<input name="search_term" id="search_term" type="text" style="height:23px; margin-right:20px;font-size: 16px" value="<?PHP echo $search_term; ?>" size="36" autocomplete="off"/></td>
<td>
<input name="addressInput" id="addressInput" type="text" style="height:23px;margin-right:10px;font-size: 16px" value="<?PHP echo $location_term; ?>" size="36" autocomplete="off"/></td><td>
<select id="radiusSelect">
<option value="25" selected>25</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
</td><td>
<input type="submit" name="search_button" style= "padding: 5px; font-family: Arial, Helvetica, sans-serif; font-size: 12px;" value="Search" onClick="searchLocations();" />
</td></tr></table>
</form>
and then here is my search_query.php
<?PHP
global $search_term;
global $location_term;
global $results;
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$connection_string = "connectionstring.php";
require_once($connection_string);
mysql_select_db("chef") or die ( 'Unable to select database.' );
$RESULTS_LIMIT=5;
if(isset($_GET['search_term']) && isset($_GET['addressInput']) && isset($_GET['search_button']))
{
$search_term = $_GET['search_term'];
$location_term = $_GET['addressInput'];
if(isset($_GET['first_pos']))
{
$first_pos = $_GET['first_pos'];
}
else
{
$first_pos = 0;
}
$start_search = getmicrotime();
$sql_query = mysql_query("SELECT * FROM searchengine WHERE MATCH(product) AGAINST('$search_term') AND MATCH(location) AGAINST('$location_term')");
if($results = mysql_num_rows($sql_query) != 0)
{
$sql = "SELECT * FROM searchengine WHERE MATCH(product) AGAINST('$search_term') AND MATCH(location) AGAINST('$location_term') LIMIT $first_pos, $RESULTS_LIMIT";
$sql_result_query = mysql_query($sql);
}
else
{
$sql = "SELECT * FROM searchengine WHERE (product LIKE '%".mysql_real_escape_string($search_term)."%' AND location LIKE '%".mysql_real_escape_string($location_term)."%') ";
$sql_query = mysql_query($sql);
$results = mysql_num_rows($sql_query);
$sql_result_query = mysql_query("SELECT * FROM searchengine WHERE (product LIKE '%".$search_term."%' AND location LIKE '%".$location_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");
}
$stop_search = getmicrotime();
$time_search = ($stop_search - $start_search);
}
?>
This is my pagination.php
<?PHP
global $first_pos;
global $sites;
if($first_pos > 0)
{
$back=$first_pos-$RESULTS_LIMIT;
if($back < 0)
{
$back = 0;
}
echo "<a href='index2.php?search_term=".stripslashes($search_term)."&addressInput=$location_term&search_button=Search&first_pos=$back' ></a>";
}
if($results>$RESULTS_LIMIT)
{
$sites=intval($results/$RESULTS_LIMIT);
if($results%$RESULTS_LIMIT)
{
$sites++;
}
}
for ($i=1;$i<=$sites;$i++)
{
$fwd=($i-1)*$RESULTS_LIMIT;
if($fwd == $first_pos)
{
echo "<a href='index2.php?search_term=".stripslashes($search_term)."&addressInput=$location_term&search_button=Search&first_pos=$fwd '><b>$i</b></a> | ";
}
else
{
echo "<a href='index2.php?search_term=".stripslashes($search_term)."&addressInput=$location_term&search_button=Search&first_pos=$fwd '>$i</a> | ";
}
}
if(isset($first_pos) && $first_pos < $results-$RESULTS_LIMIT)
{
$fwd=$first_pos+$RESULTS_LIMIT;
echo "<a href='index2.php?search_term=".stripslashes($search_term)."&addressInput=$location_term&search_button=Search&first_pos=$fwd ' > >></a>";
$fwd=$results-$RESULTS_LIMIT;
}
?>
</td>
</tr>
</table>
I was wondering how to make this search engine not refresh?