Hi everybody, im trying the following code to search for a string in the database. it is working fine. the problem is when i enter string for example "hello" this will look for hello in the database and if i enter "hello world" then i will look for hell world instead of hello and world. i want it to look for both hello and world. how i can do this. i want user to be able to find with the string and if the all string or any word of the string is available in the database then the results should be passed. i will be thankful if any help will be given to me.
thanking you.
thanking you.
Code:
if($_REQUEST["key"] != ""){
$key = $_REQUEST["key"];
$q = "SELECT * FROM contents WHERE title LIKE '%".$key."%' OR content LIKE '%".$key."%'";
$r = mysql_query($q);
echo "We have found these pages that contain the entered keyword(s).<br/><br/>";
while($rw = mysql_fetch_assoc($r)){
if($rw["name"]=="home") $link = "index.php";
else $link = "page.php?pg=" . $rw["name"];
echo "Page: <a class='readmore' href='".$link."'>".$rw["title"]."</a><br/><br/>";
echo "Content :- " . str_replace($key,"<b><u>$key</u></b>",substr(strip_html_tags($rw["content"]),0,300)) . ".... <br /><br />";
}
} else
{
echo("<center><font color=red>Sorry...! Your Search Revealed No Results. Please Enter Search Keyword.</font></center>");
}
Comment