Guest User

Untitled

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