I am creating a search feature for a products catalog.
Here is the input code so far:
<form name="search" method="post" action="'.$PHP_SELF.'">
<div>
Search for: <input type="text" name="find" />
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</div>
</form>
Here is the query that queries the Mysql database for a match:
SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'
This all works perfectly fine, when the user searches for a one word string.
What the problem is here, is that when a user searches for a two word string, no match is found as sometimes these strings relate to seperate features.
An example of this would be, the products catalog contains information about various chocolates:
You get bars of chocolates, boxes of chocolates, packets of chocolates, etc…
Now although some of the descriptions held in the field desc contain the words chocolate and bar, some contain variations, like “company bars 120g chocolates”.
This causes a problem in the above code, because if a user searches “chocolate bar” unless the description in the desc field contains that variation explicitly, no matches will be returned.
What I would like to happen, is when a user searches “chocolate bar” any match containing the varitions “chocolate” and “bar” will be returned.
Does anyone have any input on how i would go about this task?
Possibily turn $find into an array and make ” ” a delimiter?
Maybe you could do something like this:
Output for
$find = 'this':Output for
$find = 'this and that':This sure is a very basic functionality, but you get the idea.