infojunkie243

search.php

Mar 17th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. $button = $_GET ['submit'];
  4. $search = $_GET ['search'];
  5.  
  6. if(!$button)
  7. echo "you didn't submit a keyword";
  8. else
  9. {
  10. if(strlen($search)<=1)
  11. echo "Search term too short";
  12. else{
  13. echo "You searched for <b>$search</b> <hr size='1'></br>";
  14. mysql_connect("localhost","webcrawler","secret");
  15. mysql_select_db("webcrawler");
  16.  
  17. $search_exploded = explode (" ", $search);
  18.  
  19.  
  20. foreach($search_exploded as $search_each)
  21. {
  22. $x++;
  23. if($x==1)
  24. $construct .="keywords LIKE '%$search_each%'";
  25. else
  26. $construct .="AND keywords LIKE '%$search_each%'";
  27.  
  28. }
  29.  
  30. $construct ="SELECT * FROM document WHERE $construct";
  31. $run = mysql_query($construct);
  32.  
  33. $foundnum = mysql_num_rows($run);
  34.  
  35. if ($foundnum==0)
  36. echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
  37. Try more general words. for example: If you want to search 'how to create a website'
  38. then use general keyword like 'create' 'website'</br>2. Try different words with similar
  39. meaning</br>3. Please check your spelling";
  40. else
  41. {
  42. echo "$foundnum results found !<p>";
  43.  
  44. while($runrows = mysql_fetch_assoc($run))
  45. {
  46. $url = $runrows ['url'];
  47. $title = $runrows ['crawl_date'];
  48. $desc = $runrows ['text'];
  49.  
  50.  
  51. echo "
  52. <a href='$url'><b>$title</b></a><br>
  53. $desc<br>
  54. <a href='$url'>$url</a><p>
  55. ";
  56.  
  57. }
  58. }
  59.  
  60. }
  61. }
  62.  
  63. ?>
Add Comment
Please, Sign In to add comment