Hi I am developping a search script for my site and I'm stuck at one part. The script I did works fine but it looks for exact matches within the fields. For example if I type "John Smith" it would return all the rows with John Smith in them. But if I type Smith John I won't get those results how should I build my search query so it would return the rows even if I switch the order of the words?
my scripts are as follow:
The form:
<table width="236" border="0" cellspacing="0" cellpadding="0">
<tr><form id="search" method="post" action="search.php">
<td width="180"><input name="keyword" type="text" id="keyword" size="30" maxlength="50"></td>
<td width="56"><input type="submit" name="Search" value="Search"></td></form>
</tr>
</table>
Search Script:
$sql=mysql_query("SELECT * FROM stories WHERE title LIKE '%".$_POST."%'
OR author LIKE '%".$_POST."%' OR content LIKE '%".$_POST."%'");
$num_results=mysql_num_rows($sql);
echo 'You have searched for: '.$keyword.'<p>Number of Results: '.$num_results.'</p>';