I have a search scripts with some basic functions like pagination, highlight the search quiree term. But what I am looking to have in the script is additional following three options.
1- When search result comes empty then it displays the Message "There is no result for the term "XYZ"" where XYZ would be a search term.
2- I should be able to identify minimum number of alphabets used in the search term. e.g. if someone search "ab" then it displays the message that "there should be minimum of 3 characters in a search term"
3- The World we search should be metioned at top & should be of different color then rest of the text in search result e.g. "result 1-10 of about 159 for "XYZ"" and on 3 page it would be e.g. "result 21-30 of about 159 for "XYZ""
4- This is not compusory but if I can have verification image option for running search then it would be amaizing...
Can someone please help me with these. Script that I have is somewhat like following
<?php
include_once("search.php");
//check to make sure that the $_GET['search'] variable is set and equal to "search" - this'll stop the server from throwing an error on first visit to the page
if((isset($_GET['search'])) || (isset($_GET['offset']))){
$keyword = $_GET['keyword'];
//check to see if an offset has been pased through - if not, this is our first results page, so we need to set the offset to 0
if(isset($_GET['offset'])){
$offset = $_GET['offset'];
}else{
$offset = 0;
}
//set up an incrementor variable to create an associative array we can crawl in the main html portion of the page later
$i=0;
$query = "SELECT * FROM ABCDEF WHERE '$VWXYZ' OR '$url' OR LMNOPQ LIKE '%$keyword%' LIMIT $offset, 10;";
//check to make sure that there are results - if not, print the error message for debugging
if($recordset = mysql_query($query)){
//find out how many records are the in the table that meet the criteria
$query2 = "SELECT COUNT(id) AS rws FROM ABCDEF WHERE '$VWXYZ' OR '$url' OR LMNOPQ LIKE '%$keyword%';";
$recordset2 = mysql_query($query2);
$line2 = mysql_fetch_assoc($recordset2);
$number_records = $line2['rws'];
//retrieve the records from our first query (with the limit clause)
while($line = mysql_fetch_assoc($recordset)){
//the foreach loop is simpler to code than manually associating each resulting record to a variable of the same name
foreach($line as $key=>$var){
$results[$i][$key] = $var;
if($key == "LMNOPQ"){
//make the keyword red and bold in the LMNOPQ result
$results[$i]['LMNOPQ'] = preg_replace("/$keyword/i", "<b><font color="red">$keyword</font></b>", $var);
}
}
//next row in the return array
$i++;
}
}else{
print(mysql_error());
}
//now we can figure out how many pages of results there are - we set the LIMIT to 10 records, so this page will always return at most 10 records
// Note that we're rounding up with the ceil() function - this will give us an additional page if there aren't a number of rows divisible evenly by 10
$pages = ceil($number_records / 10);
//now figure out which page we're on currently
$current_page = ($offset / 10) + 1;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mushy Search</title>
</head>
<body>
<form action="ABCDEF_Search.php" method="get" name="search">
<input name="search" type="hidden" value="search">
<input name="keyword" type="text" value="keyword" size="30" maxlength="30">
<input name="search" type="submit" value="search">
</form>
<br />
<?php
if(isset($_GET['offset']) || ($_GET['search'] == "search")){
for($i=0; $i<count($results); $i++){
print("<a href="".$results[$i]['url']."">".$results[$i]['title']."</a><br /><i>".$results[$i]['LMNOPQ']."</i>"."<hr />");
}
}
//here's where we set up the pagination - it's pretty simple, really. We'll use $current_page and $pages to figure out where we are and where we want to go
// check to make sure we're actually outputting a search result and this isn't the first time the page is being hit
if(isset($current_page)){
// if the page we're on is not the first page of results, display the previous link
// (subtract 10 from the currently set offset to get the new offset to pass to the query)
if($current_page > 1){
print("<a href="ABCDEF_Search.php?offset=".($offset - 10)."&keyword=$keyword">[Previous]</a> ");
}
// now we spit out page numbers for each page of the result and set up the offset to pass to the query
for($i=1; $i<=$pages; $i++){
if($i != $current_page){
// because we're starting the incrementor ($i) at 1 instead of 0, we need to subtract one before multiplying by 10 to get the actual offset for the page in question
print("<a href="ABCDEF_Search.php?offset=".(($i - 1) * 10)."&keyword=$keyword">".$i."</a> ");
}else{
// no need to have a link to the current page, right?
print("$current_page ");
}
}
// as long as the current page is not the last page in the results, display the next link
// (add 10 to the current offset to get the new offset to pass to the query)
if($current_page < $pages){
print("<a href="ABCDEF_Search.php?offset=".($offset + 10)."&keyword=$keyword">[Next]</a>");
}
}
?>
</body>
</html>
I will be highly greatful for the help...