I have been trying to get this and many others like it to work. the issue is when I submit for the search I go to a blank page… I have worked out all the kinks other than this one and it has been reoccuring regardless of which search engine code I use… Someone please help!!!
[php]
<?PHP
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//initializing connection to the database
$connection_string = dirname(__FILE__) . "/connectionstring.php";
require_once($connection_string);
//selecting table
mysqli_select_db($conn, $DB_NAME) or die ( 'Unable to select database.' );
//max number of results on the page
$RESULTS_LIMIT=10;
if(isset($_GET['search_term']) && isset($_GET['search_button']))
{
$search_term = $_GET['search_term'];
if(!isset($first_pos))
{
$first_pos = "0";
}
$start_search = getmicrotime();
//initializing mysqli Quary
$sql_query = mysqli_query("SELECT * FROM news WHERE MATCH(title,article) AGAINST('$search_term')");
//additional check. Insurance method to re-search the database again in case of too many matches (too many matches cause returning of 0 results)
if($results = mysqli_num_rows($sql_query) != 0)
{
$sql = "SELECT * FROM news WHERE MATCH(title,article) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
$sql_result_query = mysqli_query($sql);
}
else
{
$sql = "SELECT * FROM news WHERE (title LIKE '%".mysqli_real_escape_string($search_term)."%' OR article LIKE '%".$search_term."%') ";
$sql_query = mysqli_query($sql);
$results = mysqli_num_rows($sql_query);
$sql_result_query = mysqli_query("SELECT * FROM news WHERE (title LIKE '%".$search_term."%' OR article LIKE '%".$search_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");
}
$stop_search = getmicrotime();
//calculating the search time
$time_search = ($stop_search - $start_search);
}
?>
<?PHP
if($results != 0)
{
?>
When you’re developing you should make sure your local dev environment is set up to show all errors. A white page is what PHP defaults to when it hits any “500 internal server error” that isn’t properly handled by the application.
An easy way to activate all is to add this to the beginning of your script
[php]error_reporting(E_ALL);
ini_set(‘display_errors’, 1);[/php]
Though this should really be changed in your local php.ini