PDA

View Full Version : How do I...MySQL %LIKE% query


eblivion
Sat 16th Oct '04, 12:53pm
How do I query the database using LIKE for an array but getting only results containing the full words instead of parts of it.

Here's a little chunk of what I have so far:

$keywords = explode(' ',$searchterm) ;

for ($i = 0; $i < sizeof($keywords); $i++){
$sql5b .= "description LIKE '%{$keywords[$i]}%'";
}

I have the query working, the problem is if one of the keywords is "class", the query will return results for: class, classic, midclass, classify, etc....

What I want to know is how to do the query where it will only return results for the word class and not other words containing it.

galois
Thu 21st Oct '04, 3:17am
If you have an array of seach words {"keyword1, keyword2, ...."} you can have a query in the following form:

SELECT .... FROM .... WHERE (description = '$keyword1') OR (description = '$keyword2') OR ....


LIKE in conjunction with % selects items that partially match your search criteria.

LIKE %class => midclass, no-class
LIKE class% => classic, classmates


Tell me if this is helpfull.

Best Regards