Jump to content

[SOLVED] Like clause


Jonob

Recommended Posts

I have a table with something like the following structure:

 

id (PK)

search_term (varchar 15)

 

What I would like to do is find all occurences of matching search_term.

 

For example, lets assume that I have the following records:

id, search_term

1, Maple

2, Oak

3, Elm

 

What I would like to do is pass in something like "Red Maple Tree", and it would return

1, Maple

 

Or "Oak roots" would return

2, Oak

 

Or "El" would return

null

 

I have tried

SELECT id, search_term
FROM import_rule
WHERE %search% LIKE "Red Maple Tree"

but this obviously fails.

 

Any help greatly appreciated.

Link to comment
Share on other sites

OK, gotcha.

 

I exploded the search term into an array in php, and created my WHERE statement using each value in the array.

 

i.e. WHERE (seach_term LIKE '%Red%' OR seach_term LIKE '%Maple%' OR seach_term LIKE '%Tree%')

 

Works perfectly, thanks Fenway

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.