- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body style="font-family:Courier">
- <?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
- mysql_select_db("kutuphane") or die ( 'Unable to select database.' );
- //max number of results on the page
- $RESULTS_LIMIT=5;
- 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 MySQL Quary
- $sql_query = mysql_query("SELECT * FROM mesajlar WHERE MATCH(isim,mesaj) 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 = mysql_num_rows($sql_query) != 0)
- {
- $sql = "SELECT * FROM mesajlar WHERE MATCH(isim,mesaj) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
- $sql_result_query = mysql_query($sql);
- }
- else
- {
- $sql = "SELECT * FROM mesajlar WHERE (isim LIKE '%".mysql_real_escape_string($search_term)."%' OR mesaj LIKE '%".$search_term."%') ";
- $sql_query = mysql_query($sql);
- $results = mysql_num_rows($sql_query);
- $sql_result_query = mysql_query("SELECT * FROM mesajlar WHERE (isim LIKE '%".$search_term."%' OR mesaj 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)
- {
- ?>
- <!-- Displaying of the results -->
- <?PHP echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?>için arama sonuçları |
- Results <b>
- <?PHP echo ($first_pos+1)." - ";
- if(($RESULTS_LIMIT + $first_pos) < $results) echo ($RESULTS_LIMIT + $first_pos);
- else echo $results ; ?>
- </b>
- out of <b><?PHP echo $results; ?></b>
- for(<b><?PHP echo sprintf("%01.2f", $time_search); ?></b>)
- seconds </td>
- <form action="" method="GET">
- <input name="search_term" type="text" value="<?PHP echo $search_term; ?>" size="40">
- <input name="search_button" type="submit" value="Search">
- </form>
- <?PHP
- while($row = mysql_fetch_array($sql_result_query))
- {
- ?>
- <p><b><?PHP echo $row['isim']; ?></b><p><?PHP echo $row['mesaj']; ?><hr style="border-top:dashed 1px;border-bottom:none;">
- <?PHP
- }
- ?>
- <?PHP
- }
- //if nothing is found then displays a form and a message that there are nor results for the specified term
- elseif($sql_query)
- {
- ?>
- <?PHP echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?> bulunamadı
- <form action="" method="GET">
- <input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
- <input name="search_button" type="submit" value="Search">
- </form>
- <?PHP
- }
- ?>
- <?php
- if (!isset($_GET['search_term'])) { ?>
- <form action="" method="GET">
- <input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
- <input name="search_button" type="submit" value="Search">
- </form>
- <?php
- }
- ?>
- <?PHP
- //displaying the number of pages where the results are sittuated
- if($first_pos > 0)
- {
- $back=$first_pos-$RESULTS_LIMIT;
- if($back < 0)
- {
- $back = 0;
- }
- echo "<a href='search.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='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd '><b>$i</b></a> | ";
- }
- else
- {
- echo "<a href='search.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="./search.php?search_term='.stripslashes($search_term)."&first_pos=$fwd".' " > >></a>';
- $fwd=$results-$RESULTS_LIMIT;
- }
- ?>
- </body>
- </html>