rogerzebra
Technical User
Hi again everyone..
I found this script on a search engine and I tried to implement it on my intranet but it doesn't work, so I would appreciate if someone could take a look at it and help me to figure it out of what's wrong with it. It givs me a error on line 71.
I thought it would be good for me to put up the whole script in case of there is any other faults. So thanks in advance for any input and I would be most grateful if someone could explain parts of the code I don't get. (marked in red...)..I actually thought is was more than one script??..I know it's possible to use several php tags in one script bot beneth the </html> end tag?
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);
}
else
{
getKeywords();
}
function getKeywords()
{
}
function doSearch($search_keywords)
{
}
function getKeywords()
{
?>
<html>
<head><title> Enter Search Keywords </title></head>
<body bgcolor="#FFFFFF">
<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>
</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='searchdocs.php'>Go Back</a>";
}
else
{
// Connect to the database
$dbhost = 'localhost';
$dbusername = 'root';
$dbpasswd = 'matrix';
$database_name = 'intranet';
$s = @mysql_connect($dbhost, $dbusername, $dbpasswd)
or die("Couldn't connect to database server");
@mysql_select_db($database_name, $s)
or die("Couldn't connect to database");
for($i = 0; $i < sizeof($arrWords); $i++)
{
$query = "select articleIds from searchWords where word = '{$arrWords[$i]}'"; [color]
$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;
//Each article returned from the select query is added to an associative array called $articles:
$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++;
}
}
//At this point, the $articles associative array will contain all of the articles returned from the search.
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]; ?>">
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>";
}
}
}
}
?>
It refer to a link article.php in this script but in the tutorial they never mentioned to make a article.php page or am I reading this wrong?...or am I supposed to change that to searchdocs.php??
This is the original script and I haven't done any changes to it.
I'm greatful for any help on this or open to suggestions to another script regarding search engines for pulling data from your database.
/rz
I found this script on a search engine and I tried to implement it on my intranet but it doesn't work, so I would appreciate if someone could take a look at it and help me to figure it out of what's wrong with it. It givs me a error on line 71.
I thought it would be good for me to put up the whole script in case of there is any other faults. So thanks in advance for any input and I would be most grateful if someone could explain parts of the code I don't get. (marked in red...)..I actually thought is was more than one script??..I know it's possible to use several php tags in one script bot beneth the </html> end tag?
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);
}
else
{
getKeywords();
}
function getKeywords()
{
}
function doSearch($search_keywords)
{
}
function getKeywords()
{
?>
<html>
<head><title> Enter Search Keywords </title></head>
<body bgcolor="#FFFFFF">
<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>
</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='searchdocs.php'>Go Back</a>";
}
else
{
// Connect to the database
$dbhost = 'localhost';
$dbusername = 'root';
$dbpasswd = 'matrix';
$database_name = 'intranet';
$s = @mysql_connect($dbhost, $dbusername, $dbpasswd)
or die("Couldn't connect to database server");
@mysql_select_db($database_name, $s)
or die("Couldn't connect to database");
for($i = 0; $i < sizeof($arrWords); $i++)
{
$query = "select articleIds from searchWords where word = '{$arrWords[$i]}'"; [color]
$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;
//Each article returned from the select query is added to an associative array called $articles:
$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++;
}
}
//At this point, the $articles associative array will contain all of the articles returned from the search.
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]; ?>">
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>";
}
}
}
}
?>
It refer to a link article.php in this script but in the tutorial they never mentioned to make a article.php page or am I reading this wrong?...or am I supposed to change that to searchdocs.php??
This is the original script and I haven't done any changes to it.
I'm greatful for any help on this or open to suggestions to another script regarding search engines for pulling data from your database.
/rz