Guest User

Untitled

a guest
Jun 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <?php
  2. $submit = $_POST["submit"];
  3. $keywords = $_POST["keywords"];
  4.  
  5. if(isset($submit) || isset($keywords))
  6. {
  7. doSearch($keywords);
  8. }
  9. else
  10. {
  11. getKeywords();
  12. }
  13.  
  14. function getKeywords()
  15. {
  16. ?>
  17. <html>
  18. <head>
  19. <title>Search</title>
  20. </head>
  21. <body bgcolor="#000000">
  22. <form name="frmKW" action="search.php" method="post">
  23. <h1>Keyword Search</h1>
  24. Enter keywords to search on:
  25. <input type="text" name="keywords" maxlength="100">
  26. <br><br><input type="submit" name="submit" value="Search">
  27. </form>
  28. </body>
  29. </html>
  30. <?php
  31. }
  32.  
  33. function doSearch($search_keywords)
  34. {
  35. $arrWords = explode(" ", $search_keywords);
  36.  
  37. if(sizeof($arrWords) == 0 || $search_keywords == "")
  38. {
  39. echo "You didn't enter any keywords<br>";
  40. echo "<a href='searchd.php'>Go Back</a>";
  41. }
  42. else
  43. {
  44. // Connect to the database
  45. $dServer = "localhost";
  46. $dDb = "nakedpr1_Search";
  47. $dUser = "nakedpr1";
  48. $dPass = "jimmyde39688635!";
  49. $s = @mysql_connect($dServer, $dUser, $dPass)
  50. or die("Couldn't connect to database server");
  51. @mysql_select_db($dDb, $s)
  52. or die("Couldn't connect to database");
  53.  
  54. for($i = 0; $i < sizeof($arrWords); $i++)
  55. {
  56. $query = "select articleIds from searchWords where word = '{$arrWords[$i]}'";
  57. $result = mysql_query($query);
  58.  
  59. if(mysql_num_rows($result) > 0)
  60. {
  61. // Get the id's of the articles
  62. $row = mysql_fetch_array($result);
  63. $arrIds = explode(",", $row[0]);
  64. $arrWhere = implode(" OR articleId = ", $arrIds);
  65. $aQuery = "select articleId, url, title, left(content, 100) as summary, url from articles where articleId = " . $arrWhere;
  66. $aResult = mysql_query($aQuery);
  67. $count = 0;
  68. $articles = array();
  69.  
  70. if(mysql_num_rows($aResult) > 0)
  71. {
  72.  
  73. while($aRow = mysql_fetch_array($aResult))
  74. {
  75. $articles[$count] = array (
  76. "articleId" => $aRow["articleId"],
  77. "title" => $aRow["title"],
  78. "summary" => $aRow["summary"],
  79. "url" => $aRow["url"]
  80. );
  81. $count++;
  82. }
  83. }
  84.  
  85. if(isset($articles))
  86. {
  87. $articles = array_unique($articles);
  88. echo "<h1>" . sizeof($articles);
  89. echo (sizeof($articles) == 1 ? " article" : " articles");
  90. echo " found:</h1>";
  91.  
  92. foreach($articles as $a => $value)
  93. {
  94. ?>
  95. <a href="<?=$articles[$a]["url"]?> ">
  96. <b><u><?php echo $articles[$a]["title"]; ?></u></b>
  97. </a>
  98. <br><?php echo $articles[$a]["summary"] . "..."; ?>
  99. <br>
  100. <a href="<?=$articles[$a]["url"]?>">
  101. <?=$articles[$a]["url"]?></a>
  102. <br><br>
  103. <?php
  104. }
  105. }
  106. else
  107. {
  108. echo "No results found for '$search_keywords'<br>";
  109. echo "<a href='search.php'>Go Back</a>";
  110. }
  111. }
  112. }
  113. }
  114. }
  115. ?>
Add Comment
Please, Sign In to add comment