Forum Moderators: coopster
if(isset($_POST["keyword"]))
{
$keyTemp = $_POST["keyword"];
if($keyTemp == null)
{
echo "You need to enter something in order to search.";
$keywords = "";
}
else
{
$string_array = explode(" ", $keyTemp);
foreach($string_array as $num => $word)
{
$new[$num] = '%' . $word . '%';
}
$keywords = implode(" ",$new);
}
}
My questions is that. How do I solve the problem of people being about to search for "wireless card" and returns results with "wireless" and "card" inside. But not "card wireless"?
I know this is because of the oder of the words appearing in the SQL query. But how do I solve this?
SELECT * FROM productcatalog_product
WHERE product_manufacturer LIKE '%corp%' and product_manufacturer like '%amd%'
How do I make that instead of doing the above code, I am still about to search for "%corp% %amd%" while the data in the database is "amd query".
Because I can't get the data "amd corp" when I search for "%corp%%amd%" but only "%amd%%corp% works...
SELECT * FROM productcatalog_product
WHERE product_manufacturer REGEXP 'corp¦amd';
However this query will find all records containing at least one word (amd or corp) and is case sensitive.
I couldn't find anything else. I think, that using WHERE product LIKE '%corp%' AND product LIKE '%amd%'; would realy give best results.
Best regards
Michal Cibor
SELECT * FROM productcatalog_product
WHERE product_manufacturer LIKE '%corp%'
and product_manufacturer LIKE '%amd%'
Where the word amd and corp can be interchangable and code still works... This is for a search engine for my site...
product LIKE %here sth%and
product LIKE %here sth% AND product LIKE %here sth%
Especially that's true if you use built in function for paginating: LIMIT. Then your query would look like:
SELECT * FROM productcatalog_product
WHERE product_manufacturer LIKE '%corp%'
and product_manufacturer LIKE '%amd%' LIMIT 20 OFFSET 0
20 is the number of rows shown and 0 is the starting result row.
Hope this solves your problem. I couldn't find in the sql manual anything more about LIKE function.
Best regards!
Michal Cibor