How to Search for specific word in text field and disply matching records

7 posts by 2 authors in: Forums > CMS Builder
Last Post: September 20, 2008   (RSS)

By Mel - September 12, 2008

Hi,

In one of my sections I have a text field called areas-covered and in this text field are multiple locations which are separated by spaces, no commas.

ie location1 location2 location3 location4 etc etc

Is there a way I can query this field and then display only records that have let's say ' location2 ' in this text field

I have got a reasonable idea of how the where clause works but is there such a thing as a ' where contains ' query

Thanks - Mel[:)]

Re: [mel] How to Search for specific word in text field and disply matching records

By Dave - September 12, 2008

Yes, you can do LIKE matches to search for a keyword in the content.

Do you need it in the where or can you put it in the url?

Try this:

yourViewer.php?areas-covered_keyword=location2
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How to Search for specific word in text field and disply matching records

By Mel - September 12, 2008

Yes, you can do LIKE matches to search for a keyword in the content.

Do you need it in the where or can you put it in the url?

Try this:

yourViewer.php?areas-covered_keyword=location2


Hello Dave,

Yes can probably put in a url or if I was to use the where statement would it be something like this

'where' => 'areas-covered = "location2"',

Thanks Mel

Re: [mel] How to Search for specific word in text field and disply matching records

By Dave - September 15, 2008

Hi Mel,

If you want to search for records that "contain" location2 you would need to use a LIKE query like this:

'where' => ' areas-covered LIKE "%location2%" ',

otherwise it would only show records that match exactly.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [mel] How to Search for specific word in text field and disply matching records

By Dave - September 19, 2008

Hi Mel,

You can add them with "OR" or "AND". Like this:

'where' => ' areas-covered LIKE "%location2%" OR
areas-covered LIKE "%location7%" OR
areas-covered LIKE "%location9%" ',


You don't need the extra spaces and enters, I just like to line things up. Also, Make sure the last condition doesn't end in OR.

Let me know if that does what you need.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] How to Search for specific word in text field and disply matching records

By Mel - September 20, 2008

Hi Mel,

You can add them with "OR" or "AND". Like this:

'where' => ' areas-covered LIKE "%location2%" OR
areas-covered LIKE "%location7%" OR
areas-covered LIKE "%location9%" ',


You don't need the extra spaces and enters, I just like to line things up. Also, Make sure the last condition doesn't end in OR.

Let me know if that does what you need.


Hi Dave,

Works like a charm thank you

Mel[:)]