
September 20th, 2007, 06:34 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 4
Time spent in forums: 27 m 8 sec
Reputation Power: 0
|
|
|
Developing A Site Search Engine With PHP And MySQL
Hello, I am working on the tutorial from this website "Developing A Site Search Engine With PHP And MySQL" by Mitchell Harper and it keeps on throwing this error when testing:
Parse error: syntax error, unexpected $end in searchdocs.php on line 125
Here is my code. (PS- I couldn't find the download link for the source files)
Code:
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);
}
else
{
getKeywords();
}
function getKeywords()
{
?>
<form name="frmKW" action="searchdocs.php" method="post">
<h1>Keyword Search</h1>
Enter keywords to search on:
<input type="text" name="keywords" maxlength="100">
<br><br><input type="submit" name="submit" value="Search">
</form>
<?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='searchdocs.php'>Go Back</a>";
}
else
{
// Connect to the database
$dServer = "localhost";
$dDb = "content";
$dUser = "root";
$dPass = "";
$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 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"]
);
$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="article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>">
<b><u><?php echo $articles[$a]["title"]; ?></u></b>
</a>
<br><?php echo $articles[$a]["summary"] . "..."; ?>
<br>
<a href="article.php?articleId=<?php echo $articles[$a]; ?>">
(URL address blocked: See forum rules)=<?php echo $articles[$a]["articleId"]; ?>
</a>
<br><br>
<?php
}
}
else
{
echo "No results found for '$search_keywords'<br>";
echo "<a href='searchdocs.php'>Go Back</a>";
}
}
}
}
?>
|