Guest User

Untitled

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