It's a search script (adding links etc. with the hand)!
<?PHP
//### Maximum results per page
$maxPerPage = 20;
if(isSet($_GET['query']) && strlen($_GET['query']) >= 1 ) {
include('connection.php');
//### Get and filter the search term entered
$searchTerm = mysql_real_escape_string($_GET['query']);
$searchTerm = explode(' ',$searchTerm);
$termCount = 0;
foreach($searchTerm AS $term) { $termCount++;
if($termCount == 1) {
$query .= " WHERE keywords LIKE '%$term%' ";
} else {
$query .= " OR keywords LIKE '%$term%' ";
}
}
//### Count total results
$totalResults = mysql_num_rows(mysql_query("SELECT * FROM search_links ".$query.""));
if(!$totalResults) {echo 'We could not find any results to match your search query.'; exit; }
//### Get inital starting point for records
$start = isSet($_GET['s']) ? (int)$_GET['s'] : 0 ;
if($start > $totalResults-1) { $start = $totalResults-1; }
//### Configure the next a prev links to conform with result count
$next = ($start+$maxPerPage)>=$totalResults ? $totalResults-1 : $start+$maxPerPage ;
$prev = ($start-$maxPerPage)<0 ? 0 : $start-$maxPerPage ;
//### Now we do the search for the results
$doSearch = mysql_query("SELECT * FROM search_links ".$query." LIMIT $start,$maxPerPage");
echo '<title>avata.rs - Search: ',implode(' ',$searchTerm),'</title>';
if(mysql_num_rows($doSearch)) {
echo 'Results for "<span class="result">',implode(' ',$searchTerm),'</span>".<br><br>';
while($result = mysql_fetch_assoc($doSearch)) {
echo '<div class="results">';
echo '<span class="resulth"><a href="',$result['link'],'">',$result['title'],'</a></span> - <span class="resultd">',$result['description'],'</span><br>';
echo '';
echo '<span class="resultl">',$result['link'],'';
echo '</div>';
}
echo '<a href="search.php?query=',implode(' ',$searchTerm),'&s=',$prev,'"><<Previous</a> ';
echo '<a href="search.php?query=',implode(' ',$searchTerm),'&s=',$next,'">Next>></a>';
} else {
//### No results so we tell them and offer another search
echo 'We could not find any results to match your search query.'; exit;
}
} else {
header('Location: index.html'); exit;
}
?>