// Copyright by Erica Andrews aka CyLiKoN JeZuZ aka Li'L CJ,
// November 1999. No one is permitted to implement this script
// or any portion of it on their site without the express written // consent
// of the author (cylikon@hotmail.com). All rights reserved.
// This script was hand-coded in PHP3 by Erica on Nov. 1999
// This is the script that searches my IIS4 site using two seperate
// tables in the mysql DB and also creates a related-content, Yahoo-style
// navigation index for my site.
?>
$similarnumber Similar sites for searchword \"$searchword\"
";
while ($myrow = mysql_fetch_array($result)) {
printf("%s
";
}
// ---- If they aren't asking to see similar sites, they are searching by keyword so...
else {
$db = mysql_connect("localhost","guest","guest");
mysql_select_db("siteindex2",$db);
// --- first lets get a count of the TOTAL number of results before showing them
/* --- Using the DISTINCT attribute in the SQL string the $searchword may occur several
times on one URL page, which would bring back the same page multiple times in the search
results....so, using the DISTINCT attribute to tell SQL not to return more than
one result with the same url. Matching the Keyword+URL combo in the 'keywords' table
to the URL+ITSGROUP combo in the 'thesites' table. The 'itsgroup' column will be
used to make the links that read "show more like this" to help the visitor pull out
other content related to their search. */
$sqlcount = "SELECT DISTINCT thesites.url,keywords.thetitle,thesites.itsgroup,thesites.thedate FROM keywords,thesites WHERE keywords.keyword LIKE '%$searchword%' AND thesites.url=keywords.url";
$resultcount = mysql_query($sqlcount);
$resultsall = mysql_numrows($resultcount);
/* Now, time to limit search hits shown per page if the total number of hits (resultsall)
exceeds 10. Also, we want to make sure that the first page of the search hits starts
at the beginning of the hits found in the $resultsall count above, so setting the
following $rowoffset variable to 0 to tell MySQL to begin reading at the very first
row of the results. If the person just initiated a new search, there won't be a $rowoffset variable in the query string, so in that case we are setting it to zero. If the $rowoffset variable exists, we need to add 1 to it to get it ready for the next page of matches (i.e. if we just saw matches 11-20, lets move on to 21-30,etc.) - This is done later on with the $startrow and $rowstart variables */
if (!isset($rowoffset)) { $rowstart = '0';} else {$rowstart = $rowoffset ;}
// -- setting hits per page to 10
$matches = 10;
// -- throwing rowstart and matches into the MySQL LIMIT query
$sql = "SELECT DISTINCT thesites.url,keywords.thetitle,thesites.itsgroup,thesites.thedate FROM keywords,thesites WHERE keywords.keyword LIKE '%$searchword%' AND thesites.url=keywords.url LIMIT $rowstart,$matches";
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);
$myrow = mysql_fetch_array($result);
$url = $myrow["url"];
$title = $myrow["thetitle"];
$itsgroup = $myrow["itsgroup"];
$thedate = $myrow["thedate"];
$result = mysql_query("SELECT DISTINCT thesites.url,keywords.thetitle,thesites.itsgroup,thesites.thedate FROM keywords,thesites WHERE keyword LIKE '%$searchword%' AND thesites.url=keywords.url LIMIT $rowstart,$matches",$db);
// -------Tell them how many search results were found
// ------ First dealing with unsuccessful searches....
$nextshow = $rowstart+$matches;
if ($nextshow > $resultsall) {$nextshow = $resultsall; }
$thrurow = $nextshow;
$startrow = $rowstart+1;
if ($resultsall == '0') { echo "
That REALLY sucks! No results for \"$searchword\" found. Try a new search:
"; }
// ----- Now dealing with the successful searches
else { echo "
Your search for \"$searchword\" found $resultsall matches, showing $startrow thru $thrurow
"; }
// ----------
/* if the total results found in $resultsall exceed 10, print out a special "Next Page"
link (created under the $nextshow variable) to be shown when the results are echoed below, otherwise, show nothing special ('')...also stopping the search from trying to show
more matches than are really available */
if ($resultsall > '10' && $nextshow < $resultsall) {
echo "
\n", $myrow["url"], $myrow["thetitle"],$myrow["thedate"],$myrow["itsgroup"]); }
// ---- Repeating from above to show a "Next Page" link at the bottom of the page
if ($resultsall > '10' && $nextshow < $resultsall) {
echo "
"; }
// --- making sure we aren't showing two search forms at the bottom of the
//--- on the "unsucessfull searches" pages
if ($resultsall != '0') {
echo "";
echo "
"; }
// ---- ending this long ass 'if-else' statement
}
?>