help! for my project...
| From: | Jeffrey S. Payao | Date: | Mon, 24 Feb 2003 08:59:12 +0000 |
| Subject: | help! for my project... | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-18683@lists.php.net to get a copy of this message | ||
hi guys! can anyone please help me in my project. please. im currently creating my thesis, a site with a search engine. i googled and found a lot for my projects. now my problem is i cant display my article links. :( im using php+apache+mysql on my w2k. here are the following code i took from http://www.devarticles.com/
the sql:
create database content;
use content;
create table articles
(
articleId int auto_increment,
title varchar(50) not null,
content text,
primary key(articleId),
unique id(articleId)
);
create table searchWords
(
wordId int auto_increment,
word varchar(50),
articleIds varchar(255),
primary key(wordId),
unique id(wordId)
);
insert into articles values(0, 'MySQL is a great database', 'If you\'re after a top quality database, then you should consider MySQL. MySQL is packed with features, and can be installed on both Linux and Windows servers.');
insert into searchWords values(0, 'MySQL', '1');
insert into searchWords values(0, 'install', '1');
insert into articles values(0, 'MySQL: Most popular DBMS!', 'A recent survey conducted by Company X indicated that 98% of Linux developers prefer MySQL over any other DBMS. Developers prefer MySQL because it is fast, free and also cross-platform.');
update searchWords set articleIds = '1,2' where word = 'MySQL';
insert into searchWords values(0, 'survey', 2);
insert into articles values(0, 'Apache is pronounced A-Patchy', 'Did you know that Apache is pronounced A-Patchy, because back in its early days it consisted of code that was just \'patched\' together roughly to create a web server?');
insert into searchWords values(0, 'apache', 3);
the php:
<?php
$submit = $_POST["submit"];
$keywords = $_POST["keywords"];
if(isset($submit) || isset($keywords))
{
doSearch($keywords);} else {
getKeywords();} 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
$dServer = "localhost";
$dDb = "content";
$dUser = "admin";
$dPass = "password";
$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");
$count = 0;
$articles = array();
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);
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]; ?>">
http://localhost/article.php?articleId=<?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>";
}
}} ?> can anybody please point me out on how to display the articles? thaks in advance... jeff...