php mysql query where description like any of the word in the given string?

Almost all website having a search field on the top it will search in the entire database and display related data in the user when user type a group of word almost all case user will not get accurate report,because the MySQL query using the LIKE “%$query%/”,so in this tutorial we are planning to elaborate how to search word by word in the database for given string.

#search Form

<form action="search.php" method="post">
<input type="text" name="q" value="">



$searchQ=explode(' ',$q );
foreach($searchQ as $key=>$value)
$searchquery.="description LIKE %".$value."%"
$searchquery.=" OR description LIKE %".$value."%"
$query="SELECT * FROM leads WHERE ".$searchquery;
you can use this query to fetch the data

Leave a Reply

Your email address will not be published. Required fields are marked *