URL phrase for multiple keywords

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 12, 2011   (RSS)

Re: [degreesnorth] URL phrase for multiple keywords

By Jason - January 7, 2011

Hi,

There currently isn't a way to have CMS Builder automatically search 1 field for multiple values. However, we can set this up with just a little extra coding.

From the look of your URL I'm assuming the field country_list is a single value drop down field. I'm also going to assume that the name of your section is "tours".

We're going to construct our URL to use comma separated values like this:
tours_summary.php?country_list=Turkey,Egypt,Syria,Jordan

Next, we're going to capture this list in our php code and use it to create a custom where clause:

$where = "1";

foreach(explode(",",@$_REQUEST['country_list']) as $country){
$where.=" OR country_list LIKE '%".mysql_escape($country)."%'";
}


Finally, we use our where clause to select our records

list($tourRecords,$tourMetaData)=getRecords(array(
'tableName' => 'tours',
'allowSearch' => false,
'where' => $where
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] URL phrase for multiple keywords

Hi Jason
Ummm, where do I put this code? I am assuming on the page where I want the result to appear? And I've tried every variation of this order, and keep getting errors. Is the order it's supposed to appear in?

Alternatively, I was wondering whether the "where" or "limit" can achieve the same thing? The country_list is a seperate table, where the field name "title" is the where the country name is inserted. Would this work as this sort of makes more sense, but I can't get this kind of phrase to work and there's nothing similar on the forum.

Thanks

Re: [degreesnorth] URL phrase for multiple keywords

By Jason - January 12, 2011

Hi,

Limit just takes in a number to limit the number of records that are returned, so this wouldn't help with what you're trying to do.

What is the error you're getting? The code I gave you would appear in the order I showed.

What is the name of the field in tours that you're trying to search? What type of field is it? If it's a list field, what is the option value of that list?

Let me know and we'll see what we can do. If you could also attach the .php file you're working with, I can take a look at that too.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/