Hello,
I got my search engine working and it does show the number of results including the number of pages it should have. But I'm having trouble outputting the results when I click next. When I click the next page it doesn't show any results.
<?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=10;
if(isset($_GET['search_term']) && isset($_GET['location_term']) && isset($_GET['search_button']))
{
$search_term = $_GET['search_term'];
$location_term = $_GET['location_term'];
if(!isset($first_pos))
{
$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);
}
?>
<?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)."&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)."&first_pos=$fwd '><b>$i</b></a> | ";
}
else
{
echo "<a href='index2.php?search_term=".stripslashes($search_term)."&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)."&first_pos=$fwd ' > >></a>";
$fwd=$results-$RESULTS_LIMIT;
}
?>
Can anyone help me out on this?
Also, I think my search doesn't get passed to the next page. Any idea how to preserve that?
Thanks