Jennifer, you're probably familiar with Unix regular expressions (like
you'll find in sed, grep, etc.). Here's what LIKE is like, in terms
of regexps.
LIKE "foo" /^foo$/ (same as = "foo" in SQL)
LIKE " foo " /^ foo $/ (same as = " foo ")
LIKE "%foo" /foo$"
LIKE "foo%" /^foo/
LIKE "%foo%" /foo/
LIKE "% foo %" / foo /
So, if you don't use any special characters (%, _) in the string after
LIKE, then LIKE behaves the same way = behaves.
I can't think of a good way to handle word boundaries using LIKE (so
that LIKE "%discover%" will match "Discover the world!" but not "I
discovered the world!" There probably is a good way to do it, but
it's escaping me right now.
Tim
At 12:48, 19990804, toxalot@stripped wrote:
>I'm having trouble understanding how LIKE works.
>
>IF I use
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "$keyword"
>
>It should match only instances of discover and not discovery, right?
>
>Will it match discover even if the instances of discover has a space on
>each side?
>
>The above gives me no results.
>
>Or do I have to use
>
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>I've tried a few different scenarios and I can't seem to get consistent
>results.
>
>IF I try
>
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>I get all kinds of matches, but if $keyword = ' discover '; I get 2 matches.
>
>I thought that
>
>$keyword = ' discover ';
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>and
>
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "$keyword"
>
>would be the same results.
>
>Thanks for your help
>
>Jennifer