Yehonatan

Simple search engine

Nov 9th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <html>
  2. <body>
  3. <?php
  4. $dbuser = "";
  5. $dbpassword = "";
  6. $dbhost = "localhost";
  7. $table = "table"; //use the results table
  8. $field = "term" //use the place where terms are.
  9. $count = 0;
  10.  
  11.  
  12. mysql_connect($dbhost,$dbuser,$dbpassword) or die("Error:" . mysql_error());
  13.  
  14. mysql_select_db("", $con);
  15.  
  16. $field_to_search = "field";
  17. if(isset($_GET['q']) && trim($_GET['q']) != '')
  18.  {
  19.   $var = $_GET['q'] ;
  20.    $query = "SELECT * FROM `$account` WHERE `$field` LIKE "%$var%" ORDER BY `id`";
  21.    $result = mysql_query($query);  
  22.    $results_num = mysql_num_rows($result);
  23.    
  24.     if($results_num = 0 || $results_num < 1)
  25.      {
  26.      
  27.        echo "No results found,please search again.";
  28.      
  29.      }
  30.    
  31.     else{
  32.    
  33.         while ($r= mysql_fetch_array($result))
  34.             {
  35.                 $count++;
  36.        
  37.                 $id = $r["id"];
  38.                 $year = $r["year"];
  39.                 $date = $r["date"];
  40.                 $title = $r["title"];
  41.                 $description = $r["description"];
  42.  
  43.  
  44.                 echo "<a href=\"http://www.websiteurl/index" . $year . "/" . $id ".html\">$title</a>";
  45.  
  46.                 echo $description
  47.                 echo "Result Number:" . $count;
  48.    
  49.             }
  50.    
  51.     }
  52.    
  53.  }
  54.  
  55.   else{
  56. ?>
  57. <p>Please enter a search...</p>
  58. <form name="search" method="GET" action="<?=$PHP_SELF?>">
  59. Search all the newsletters for  
  60. <input type="text" name="q" />
  61. <input type="submit" name="search" value="Search" />
  62. </form>
  63. <?php
  64.  
  65.  }
  66.  
  67. ?>
  68.  
  69. </body>
  70. </html>
  71.  
Advertisement
Add Comment
Please, Sign In to add comment