Search/filter question

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 21, 2016   (RSS)

I am working a list filter for a client and I'm not sure how to accomplish something.

I have a Section (grades) that includes a multl-value checkbox list (melt_types). In the CMS the administrator can select as many melt_types as they want for each grade. 

On the live site, I want the site users to be able to filter the list of grades by as many melt_types as they want.

I have filtering via the URL working one for melt_type...
/grades.php?melt_type=1

And I tried this, but it doesn't quite work, because it filters down to the grades that have both melt types selected...
/grades.php?melt_type=1&melt_type=2

I need a method that results in an OR condition, not AND.

Possible? 

Any thoughts on this?

By ross - November 17, 2016

Hi there.

Thanks for posting.

What you will need to do is create a custom "WHERE" and use that to filter the results. 

The custom "WHERE" will be where you can use the "OR" searches:

"where" => "melt_type = 1 OR melt_type = 2 OR melt_type = 3"

How comfortable are you with custom "WHERE"?

Let me know what you think.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By ross - November 21, 2016

Hi there.

You can build a custom query using values from the query string using $_REQUEST.

It could look something like this:

$customWHERE = "";

$customWHERE =  "melt_type = ". mysql_escape(@$_REQUEST['melt_type']);
$customWHERE .= " OR melt_type = ". mysql_escape(@$_REQUEST['melt_type']);

And then in your getRecords, you would use something like this:

// load records from 'another_multi_section'
list($another_multi_sectionRecords, $another_multi_sectionMetaData) = getRecords(array(
  'tableName' => 'another_multi_section',
  'loadUploads' => true,
  'allowSearch' => false,
  'where'       => $customWHERE ,
));

A couple notes:

1. Make sure you have "allowSearch" set to "False". If that's true, the search you get will be a composite of what's in the query string as well as the custom WHERE.

2. You can create your $customWHERE on a single line if you like. I broke my example into two lines so it's easier to read in a forum post.

Does that all make sense?

Let me know any questions.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/