Filter results based on checkboxes list

9 posts by 2 authors in: Forums > CMS Builder
Last Post: September 25, 2013   (RSS)

By Jason - September 25, 2013

Hi Jesus,

CMS Builder stores multi-value lists as strings separated by tab (\t) characters.  So, if your "application" field is a checkbox list, you can change your where clause like this:

// load records from 'ssbr'
  list($ssbrRecords, $ssbrMetaData) = getRecords(array(
    'tableName'   => 'ssbr',
    'where'       =>  "application LIKE '%\tPolymer Modification\t%' ",
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
  ));

Give this a try and let me know if this gives you the results you are expecting.

Thanks

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By Jesus - September 25, 2013

Awesome Jason!!! it worked nicely!

Thanks for your help!

By Jesus - September 25, 2013

Now, I've another question.... sorry.

As I've just one detail.php page to display my content and I've 6 different kind of applications on my list.

How can I create an IF statement or something similar to display the products I need?

Right now, if I code it directly it works with no issues but that covers me just one kind of products, how can I do that if?.... at the moment I'm writing I'm also thinking....

Thanks for your help!

By Jesus - September 25, 2013

ok... i think I'm close...

Based on the Title, I can create an if statement to get the proper value, something like this...

if ($applicationsRecord['title'] == "Polymer Modification") {
    $whereName = '%\tPolymer Modification\t%';
  }
  elseif ($applicationsRecord['title'] == "Adhesives") {
    $whereName = '%\tAdhesives\t%';
  }
  elseif ($applicationsRecord['title'] == "Asphalt/Bitumen") {
    $whereName = '%\tAsphalt/Bitumen\t%';
  }
  elseif ($applicationsRecord['title'] == "Compounding") {
    $whereName = '%\tCompounding\t%';
  }
  elseif ($applicationsRecord['title'] == "Sealants") {
    $whereName = '%\tSealants\t%';
  }
  else {
    $whereName = '%\tVulcanized Compounds\t%';
  }

and then, below this code, I've this:

  // load records from 'ssbr'
  list($ssbrRecords, $ssbrMetaData) = getRecords(array(
    'tableName'   => 'ssbr',
    'where'       =>  "application LIKE 'whereName' ",
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
  ));

but for some reason, I'm not getting any results. I'm probably missing something.

Thanks for your help!

Jesus

By Jason - September 25, 2013

Hi Jesus,

It looks like you just left off the $ from $whereName in your where clause:

 // load records from 'ssbr'
  list($ssbrRecords, $ssbrMetaData) = getRecords(array(
    'tableName'   => 'ssbr',
    'where'       =>  "application LIKE '$whereName' ",
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
  ));

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/

By Jesus - September 25, 2013

Hi Jason,

I made this modification, but still no luck...

if ($applicationsRecord['title'] == "Polymer Modification") {
    $whereName = 'Polymer Modification';
  }
  elseif ($applicationsRecord['title'] == "Adhesives") {
    $whereName = 'Adhesives';
  }
  elseif ($applicationsRecord['title'] == "Asphalt/Bitumen") {
    $whereName = 'Asphalt/Bitumen';
  }
  elseif ($applicationsRecord['title'] == "Compounding") {
    $whereName = 'Compounding';
  }
  elseif ($applicationsRecord['title'] == "Sealants") {
    $whereName = 'Sealants';
  }
  else {
    $whereName = 'Vulcanized Compounds';
}

  // load records from 'ssbr'
  list($ssbrRecords, $ssbrMetaData) = getRecords(array(
    'tableName'   => 'ssbr',
    'where'       =>  "application LIKE '%\twhereName\t%' ",
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'sbs'
  list($sbsRecords, $sbsMetaData) = getRecords(array(
    'tableName'   => 'sbs',
    'where'       =>  "application LIKE '%\twhereName\t%' ",
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
  ));

By Jason - September 25, 2013

Hi Jesus,

You're still missing the "$" in the where clause.  Try replacing

'%\twhereName\t%'

with

'%\t$whereName\t%'

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/

By Jesus - September 25, 2013

AWESOME!!

Thanks a lot for your help Jason ;)