I have a table that has a fulltext field called keywords. Keywords contains keywords for that product, so an example of the keywords might be:
Cows, grass, outdoors, cattle
Now I am using the Match / Against query in MySQL and I am having a problem. I want it so if people type in Cow that it will find the entry Cows. I have tried to add a wildcard '%' and that does not seem to work, maybe I am not doing it right. Here is where I assign the wildcard to the search terms
and here is my queryPHP Code:$search_terms = trim($_GET['search']);
$search_terms = '%' . $search_terms . '%';
$search_terms = str_replace(' ' , '% %', $search_terms);
And here is the smart function from inside the Action class.PHP Code:$sql = sprintf("SELECT COUNT(id) AS total FROM products WHERE MATCH (keywords) AGAINST(%s) ORDER BY name ASC",
$action->smart($search_terms));
$sql = @mysql_query($sql);
The main reason for me using the Fulltext match / against search is so if you type in Cow Horse that you will get ALL matches of Cow AND Horse in one query, the results page is using record sets so i need to be able to set limits AND get the same results from the query each time so that when you go to page 2 you don't get the same results as page 1.PHP Code:function smart($value)
{
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
Thanks for any help.


Reply With Quote
Bookmarks