1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. </head>
  5. <body style="font-family:Courier">
  6. <?PHP
  7. function getmicrotime() {
  8. list($usec, $sec) = explode(" ", microtime());
  9. return ((float)$usec + (float)$sec);
  10. }
  11. //initializing connection to the database
  12. $connection_string = dirname(__FILE__) . "/connectionstring.php";
  13. require_once($connection_string);
  14. //selecting table
  15. mysql_select_db("kutuphane") or die ( 'Unable to select database.' );
  16. //max number of results on the page
  17. $RESULTS_LIMIT=5;
  18. if(isset($_GET['search_term']) && isset($_GET['search_button']))
  19. {
  20. $search_term = $_GET['search_term'];
  21. if(!isset($first_pos))
  22. {
  23. $first_pos = "0";
  24. }
  25. $start_search = getmicrotime();
  26. //initializing MySQL Quary
  27. $sql_query = mysql_query("SELECT * FROM mesajlar WHERE MATCH(isim,mesaj) AGAINST('$search_term')");
  28. //additional check. Insurance method to re-search the database again in case of too many matches (too many matches cause returning of 0 results)
  29. if($results = mysql_num_rows($sql_query) != 0)
  30. {
  31. $sql = "SELECT * FROM mesajlar WHERE MATCH(isim,mesaj) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
  32. $sql_result_query = mysql_query($sql);
  33. }
  34. else
  35. {
  36. $sql = "SELECT * FROM mesajlar WHERE (isim LIKE '%".mysql_real_escape_string($search_term)."%' OR mesaj LIKE '%".$search_term."%') ";
  37. $sql_query = mysql_query($sql);
  38. $results = mysql_num_rows($sql_query);
  39. $sql_result_query = mysql_query("SELECT * FROM mesajlar WHERE (isim LIKE '%".$search_term."%' OR mesaj LIKE '%".$search_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");
  40. }
  41. $stop_search = getmicrotime();
  42. //calculating the search time
  43. $time_search = ($stop_search - $start_search);
  44. }
  45. ?>
  46. <?PHP
  47. if($results != 0)
  48. {
  49. ?>
  50. <!-- Displaying of the results -->
  51. <?PHP echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?>için arama sonuçları |
  52. Results <b>
  53. <?PHP echo ($first_pos+1)." - ";
  54. if(($RESULTS_LIMIT + $first_pos) < $results) echo ($RESULTS_LIMIT + $first_pos);
  55. else echo $results ; ?>
  56. </b>
  57. out of <b><?PHP echo $results; ?></b>
  58. for(<b><?PHP echo sprintf("%01.2f", $time_search); ?></b>)
  59. seconds </td>
  60. <form action="" method="GET">
  61. <input name="search_term" type="text" value="<?PHP echo $search_term; ?>" size="40">
  62. <input name="search_button" type="submit" value="Search">
  63. </form>
  64. <?PHP
  65. while($row = mysql_fetch_array($sql_result_query))
  66. {
  67. ?>
  68. <p><b><?PHP echo $row['isim']; ?></b><p><?PHP echo $row['mesaj']; ?><hr style="border-top:dashed 1px;border-bottom:none;">
  69. <?PHP
  70. }
  71. ?>
  72. <?PHP
  73. }
  74. //if nothing is found then displays a form and a message that there are nor results for the specified term
  75. elseif($sql_query)
  76. {
  77. ?>
  78. <?PHP echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?> bulunamadı
  79. <form action="" method="GET">
  80. <input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
  81. <input name="search_button" type="submit" value="Search">
  82. </form>
  83. <?PHP
  84. }
  85. ?>
  86. <?php
  87. if (!isset($_GET['search_term'])) { ?>
  88. <form action="" method="GET">
  89. <input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
  90. <input name="search_button" type="submit" value="Search">
  91. </form>
  92. <?php
  93. }
  94. ?>
  95. <?PHP
  96. //displaying the number of pages where the results are sittuated
  97. if($first_pos > 0)
  98. {
  99. $back=$first_pos-$RESULTS_LIMIT;
  100. if($back < 0)
  101. {
  102. $back = 0;
  103. }
  104. echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$back' ></a>";
  105. }
  106. if($results>$RESULTS_LIMIT)
  107. {
  108. $sites=intval($results/$RESULTS_LIMIT);
  109. if($results%$RESULTS_LIMIT)
  110. {
  111. $sites++;
  112. }
  113. }
  114. for ($i=1;$i<=$sites;$i++)
  115. {
  116. $fwd=($i-1)*$RESULTS_LIMIT;
  117. if($fwd == $first_pos)
  118. {
  119. echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd '><b>$i</b></a> | ";
  120. }
  121. else
  122. {
  123. echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd '>$i</a> | ";
  124. }
  125. }
  126. if(isset($first_pos) && $first_pos < $results-$RESULTS_LIMIT)
  127. {
  128. $fwd=$first_pos+$RESULTS_LIMIT;
  129. echo '<a href="./search.php?search_term='.stripslashes($search_term)."&first_pos=$fwd".' " > >></a>';
  130. $fwd=$results-$RESULTS_LIMIT;
  131. }
  132. ?>
  133. </body>
  134. </html>