Filter results based on checkboxes list
9 posts by 2 authors in: Forums > CMS Builder
Last Post: September 25, 2013 (RSS)
By Jesus - September 24, 2013
Hello,
I've a table using a list field (checkboxes multiple value), where the user can select from up to 6 options the product category each product uses. On my detail page, where I need to show just the products I need on a menu, I'm using this:
// load records from 'ssbr'
list($ssbrRecords, $ssbrMetaData) = getRecords(array(
'tableName' => 'ssbr',
'where' => "application = 'Polymer Modification' ",
'orderBy' => '', // use default database order
'loadUploads' => true,
'allowSearch' => false,
));
and where I need to show the menu this code:
<section id="side_navi-4" class="widget_side_navi">
<h2>SSBR Products</h2>
<ul class='left_navigation'>
<?php foreach ($ssbrRecords as $record): ?>
<li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
<?php endforeach ?>
</ul>
</section>
But no product it has been displayed yet... am I missing something?
I must say that on my ssbr products table each product can have multiple values from the application list values, that's why I choose a checkbox list.
Thanks for pointing me out for the right direction here.
Jesus
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
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/