If you are trying to make a script that acts like search engine in your mysql database, here is a simple snipet that you can use to accomplish this task.
This script will work like search engine, first search for the keyword from your database fields which you specify at Match function, after searching the entire search keyword then if the search keyword is more than 1 word the function then split the search term and search for each keyword.
Please take note that this search engine like script will work only if the search term is more than 3 characters and your db is not less than 4 rows.
Here is the code :
PHP Code:
<?
// Standard Connection Data.
$db_host = “localhost”;
$db_user = “”; //YOur database user name
$db_pass = “”; //your database password
$db_name = “”; //your datbaase password
$dbs = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($dbs,$db_name) or die (”Cannot connect to database”);
if(!$_POST[search]){
?>
<Form methos= “POST” action = “#”>
Search For :
<input type=”text” name = “keyword” size=”25″>
<input type=”submit” name=”search” value=”Search”>
</Form>
$sql="Select * from table where MATCH (field1,field2,field3) AGAINST ('%$_POST[keyword]%')";
$rec=mysql_query($sql) or die(mysql_error());
$datas=mysql_fetch_array($rec);
if(mysql_numrows($rec) <1){
echo "No data found from db";
}else{
echo mysql_numrows($rec). " Total search result";
do{
echo "datas[field1] <br>“;
}while($datas=mysql_fetch_array($rec));
}
}
?>