Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $submit = $_POST["submit"];
- $asubmit = $_GET["submit"];
- $keywords = $_POST["keywords"];
- $akeywords = $_GET["keywords"];
- $articleID = $_GET['articleId'];
- if(isset($submit) || isset($keywords))
- {
- doSearch($keywords);
- }
- else
- {
- getKeywords();
- }
- if(isset($asubmit) || isset($akeywords))
- {
- doSearch($akeywords);
- }
- else
- {
- getKeywords();
- }
- function getKeywords()
- {
- ?>
- <html>
- <head>
- <title>Search</title>
- </head>
- <body bgcolor="#FFFFFF">
- <form name="frmKW" action="search.php" method="post" target="mainframe">
- <h1>Keyword Search</h1>
- Enter keywords to search on:
- <input type="text" name="akeywords" maxlength="1000">
- <br><br><input type="submit" name="asubmit" value="Search">
- </form>
- </body>
- </html>
- <?php
- }
- function doSearch($search_keywords)
- {
- $arrWords = explode(" ", $search_keywords);
- if(sizeof($arrWords) == 0 || $search_keywords == "")
- {
- echo "You didn't enter any keywords<br>";
- echo "<a href='search.php'>Go Back</a>";
- }
- else
- {
- // Connect to the database
- $dServer = "localhost";
- $dDb = "nakedpr1_Search";
- $dUser = "nakedpr1";
- $dPass = "jimmyde39688635!";
- $s = @mysql_connect($dServer, $dUser, $dPass)
- or die("Couldn't connect to database server");
- @mysql_select_db($dDb, $s)
- or die("Couldn't connect to database");
- for($i = 0; $i < sizeof($arrWords); $i++)
- {
- $query = "select articleIds from searchWords where word = '{$arrWords[$i]}'";
- $result = mysql_query($query);
- if(mysql_num_rows($result) > 0)
- {
- // Get the id's of the articles
- $row = mysql_fetch_array($result);
- $arrIds = explode(",", $row[0]);
- $arrWhere = implode(" OR articleId = ", $arrIds);
- $aQuery = "select articleId, title, left(content, 100) as summary, url from articles where articleId = " . $arrWhere;
- $aResult = mysql_query($aQuery);
- $count = 0;
- $articles = array();
- if(mysql_num_rows($aResult) > 0)
- {
- while($aRow = mysql_fetch_array($aResult))
- {
- $articles[$count] = array (
- "articleId" => $aRow["articleId"],
- "title" => $aRow["title"],
- "summary" => $aRow["summary"],
- "url" => $aRow["url"]
- );
- $count++;
- }
- }
- if(isset($articles))
- {
- $articles = array_unique($articles);
- echo "<h1>" . sizeof($articles);
- echo (sizeof($articles) == 1 ? " article" : " articles");
- echo " found:</h1>";
- foreach($articles as $a => $value)
- {
- ?>
- <a href="<?=$articles[$a]["url"]?> " target="mainframe">
- <b><u><?php echo $articles[$a]["title"]; ?></u></b>
- </a>
- <br><?php echo $articles[$a]["summary"] . "..."; ?>
- <br>
- <a href="<?=$articles[$a]["url"]?>" target="mainframe">
- <?=$articles[$a]["url"]?></a>
- <br><br>
- <?php
- }
- }
- else
- {
- echo "No results found for '$search_keywords'<br>";
- echo "<a href='search.php'>Go Back</a>";
- }
- }
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment