Guest User

Untitled

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