I am new here and having a big headache. I have inherited a web site at my job. It is a site for a history magazine and I need to be able to have a search and advanced search option that allows users to search the article table by keywords. The database is already set up with an article table with a keyword row. I have no idea how to go about this. This is the script I have for calling articles up by category how can I modify it to search using that darn search box? the connection string is in my bin/html/common-header.php but I can provide it if needed.
Thanks in advance for any help!
<?
$path = "";
$pageID = "categories";
$CategoryID = $_REQUEST;
$self = $_SERVER;
// how many rows to show per page
$rowsPerPage = 20;
// if $_GET defined, use it as page number
if(isset($_GET))
{
$pageNum = $_GET;
} else {
// by default we show first page
$pageNum = 1;
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
?>
<HTML>
<HEAD>
<TITLE>Current History</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL=StyleSheet HREF="current-history-style.css" TYPE="text/css">
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<? require("bin/html/common-header.php"); ?>
<?
$categoryHeader_result = mysql(currenthistorydb, "select * from Categories where (CategoryID = $CategoryID)");
$num = mysql_numrows($categoryHeader_result);
$i = 0;
$Title = mysql_result($categoryHeader_result, $i, "CategoryName");
$article_result = mysql(currenthistorydb, "select Articles.ArticleID, Articles.Title, Articles.Author, Articles.Month, Articles.Year, Articles.Abstract, CategoryArticles.ArticleID, CategoryArticles.CategoryID from Articles, CategoryArticles where ((Articles.display = 1) and (CategoryArticles.ArticleID = Articles.ArticleID) and ( CategoryArticles.CategoryID = $CategoryID)) order by Year desc, Issue desc, page asc LIMIT $offset, $rowsPerPage");
$query = "SELECT COUNT(Articles.ArticleID) AS numrows FROM Articles, CategoryArticles where ((Articles.display = 1) and (CategoryArticles.ArticleID = Articles.ArticleID) and ( CategoryArticles.CategoryID = $CategoryID))";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row;
// echo "<br>numrow" . $numrows;
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// echo "<br>maxpage" . $maxPage;
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?ID=$CategoryID&page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?ID=$CategoryID&page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?ID=$CategoryID&page=$page\">[Next]</a> ";
$last = " <a href=\"$self?ID=$CategoryID&page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
$num = mysql_numrows($article_result);
$k = 0;
// print the page navigation link
echo "<table border=0 cellpadding=0 cellspacing=0 width=\"100%\"><tr><td><h1 align=left style=\"margin:0px;\">$Title</h1><td>";
echo "<td align=right nowrap valign=bottom>Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages<br> " . $first . $prev . $next . $last . "</td></tr></table>";
echo "<hr>";
while ($k < $num) {
echo "<p><b>" . mysql_result($article_result, $k, "Month") . " " . mysql_result($article_result, $k, "Year") . "</b><br>
<a href=\"Article.php?ID=" . mysql_result($article_result, $k, "ArticleID") . "\" class=\"title\">" . mysql_result($article_result, $k, "Title") . "</a><br>";
if ( mysql_result($article_result, $i, "Author") <> "") {
echo "<a href=\"Article.php?ID=" . mysql_result($article_result, $i, "ArticleID") . "\" class=\"author\">by " . mysql_result($article_result, $i, "Author") . "</a><br>";
}
echo mysql_result($article_result, $k, "Abstract") ."</p>";
$k++;
}
// print the page navigation link
echo "<div align=right>Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages<br> " . $first . $prev . $next . $last . "</div>";
?>
<? require("bin/html/common-footer.php"); ?>
</BODY>
</HTML>