\n";
echo "\n";
echo "\n";
echo " \n";
// Set default variable values, if they're not given as parameters
if(!$number)
$number = "25";
if(!$method)
$method = "and";
if(!$category)
$category = "All";
if(!$order)
$order = "title";
if(!$start)
$start = 0;
$sfor = addslashes($sfor);
function make_bold_word($string, $word) {
$result = "";
for($start=0;$start < strlen($string);$start++) {
if(!strcasecmp($word, substr($string, $start, strlen($word)))) {
$result .= "" . substr($string, $start, strlen($word)) . "";
$start+= strlen($word)-1;
}
else
$result .= $string[$start];
}
return $result;
}
function make_bold($string, $words) {
/* $result = "";
$temp = explode(" ", $string);
$word = $temp[0];
do {
$bold_word = $words[0];
$do_bold = 0;
do {
if(!strcasecmp($bold_word, $word)) $do_bold = 1;
} while(($bold_word = next($words)));
if(strlen($result) > 0)
$result .= " ";
if($do_bold == 1)
$result .= "$word";
else
$result .= "$word";
} while(($word = next($temp)));
return $result; */
$result = $string;
$word = $words[0];
do {
$result = make_bold_word($result, $word);
} while (($word = next($words)));
return $result;
}
// Build search string, i.e. WHERE blah blah
// We search sfor in title and description
switch($method) {
case "and":
$temp = explode(" ", $sfor);
$qstring = "((title LIKE '%".$temp[0]."%' OR description LIKE '%".$temp[0]."%')";
while(($t = next($temp))) {
$qstring .= " AND (title LIKE '%$t%' OR description LIKE '%$t%')";
}
$qstring .= ")";
break;
case "or":
$temp = explode(" ", $sfor);
$qstring = "((title LIKE '%".$temp[0]."%' OR description LIKE '%".$temp[0]."%')";
while(($t = next($temp))) {
$qstring .= " OR (title LIKE '%$t%' OR description LIKE '%$t%')";
}
$qstring .= ")";
break;
case "exact":
$temp = explode(" ", $sfor);
$qstring = "(title LIKE '%$sfor%' OR description LIKE '%$sfor%')";
break;
}
reset($temp);
if($category != "All")
$qstring .= " AND category LIKE \"$category\"";
$query = mysql_query("SELECT 1 FROM bunghole_links WHERE $qstring;");
$totalnumber = mysql_num_rows($query);
if(($order == "title") || ($order == "category"))
$query = mysql_query("SELECT id, title, category, description, date_added, hits, is_new, rating, votes FROM bunghole_links WHERE $qstring ORDER BY $order LIMIT $start, ".(strval($number)+1).";");
else
$query = mysql_query("SELECT id, title, category, description, date_added, hits, is_new, rating, votes FROM bunghole_links WHERE $qstring ORDER BY $order DESC, votes DESC LIMIT $start, ".(strval($number)+1).";");
$end = mysql_num_rows($query);
if(!$end) {
echo "No results searching for \"$sfor\". Use the form below to search again.\n";
}
else {
echo "Showing records ",$start+1," to ";
if($end == ($number+1)) echo "".$start+$end-1;
else echo "".$start+$end;
echo " out of $totalnumber records. Viewing by ",nopavla($order),". ";
if($order != "title") echo "[View by title] ";
if(($order != "category") && ($category == "All")) echo "[View by category] ";
if($order != "date_added") echo "[View by date] ";
if($order != "hits") echo "[View by hits] ";
if($order != "rating") echo "[View by rating]\n";
// Show records
// We will only show 10 records, the elevent is to see if more records exist
echo " \n";
$count = 1;
while($count <= $end) {
$result = mysql_fetch_array($query);
echo "- ".ucfirst(make_bold($result["title"], $temp))."";
echo " from ",$result["category"]," category.\n";
echo "
".make_bold($result["description"], $temp)."\n";
echo " (Added: ".convert_date($result["date_added"]).", ".$result["hits"]." hits)\n";
echo " Rating: ", $result["rating"]/100,"/10 from ".$result["votes"]." votes. [Rate It]\n";
echo " \n";
// echo " - ".ucfirst($result["title"])."";
// echo " from ",$result["category"]," category.\n";
// echo "
".$result["description"]."\n";
// echo " (Added: ".convert_date($result["date_added"]).", ".$result["hits"]." hits)\n";
// echo " Rating: ", $result["rating"]/100,"/10 from ".$result["votes"]." votes. [Rate It]\n";
// echo " \n";
$count++;
if($count == ($number+1)) break;
}
// Page menu
$numofpages = $totalnumber / $number;
settype($numofpages, "integer");
if(($totalnumber % $number)) $numofpages++;
$curpage = $start/$number;
settype($numofpages, "integer");
// if(($start % 10)) $curpage++;
$curpage++;
if($numofpages > 1) {
echo "$numofpages pages:\n";
for($count=1;$count<=$numofpages;$count++) {
if($count == $curpage) echo " $count ";
else echo " $count ";
}
// Previous - Next menu
echo ". ";
if($start >= 10)
echo "<< Previous";
if(($start >= 10) && ($end == 11))
echo " - ";
if($end == ($number+1))
echo "Next >>\n";
}
else echo " No more pages.\n";
}
echo " \n";
echo " | \n";
echo "
\n";
echo "