1

I currently have my query to have LIKE('%keyterm%'). It works fine if my data has one keyboard typed. But what if I want to type in two keywords. Then it will return false.

Example:

keyword : rock climbing
data in mysql: Rock Day Free Climb

This phrase should come out because it has Rock and Climb but it seems like LIKE is not enough?

What else would I need to get that query?

Thanks!

1
  • what about LIKE(%rock%) OR LIKE(%climbing%) or if its always first key and second key you can use rock%climbing as keyterm Commented Oct 7, 2011 at 3:26

2 Answers 2

1

You'll need to split on the whitespace and have a LIKE('%keyterm%') statement for each. See php.net/explode

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you guided me to the right direction. I figured it out
0

Return results containing either keyword1 or keyword2:

SELECT * FROM table WHERE data LIKE '%keyword1%' OR data LIKE '%keyword2%';

Return results containing both keyword1 and keyword2:

SELECT * FROM table WHERE data LIKE '%keyword1%' AND data LIKE '%keyword2%';

1 Comment

I have an OR statement in my query, and I'm searching the keyword as Rock Climbing, not rock then climbing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.