<div>[[+total]] Products</div> <form action="[[~[[*id]]]]" method="POST"> <p>Choose a Group or Groups:</p> <div id="checka"> <input type="checkbox" name="group[]" value="BRA" [[+BRA_checked]] id="checka1" onChange="this.form.submit();" /> <label for="checka1">Brackets</label> <input type="checkbox" name="group[]" value="BLK" [[+BLK_checked]] id="checka2" onChange="this.form.submit();" /> <label for="checka2">Blocks</label> <input type="checkbox" name="group[]" value="COR" [[+COR_checked]] id="checka3" onChange="this.form.submit();" /> <label for="checka3">Corbels</label> <input type="checkbox" name="group[]" value="GBR" [[+GBR_checked]] id="checka4" onChange="this.form.submit();" /> <label for="checka4">Gingerbreads</label> <input type="checkbox" name="group[]" value="WBR" [[+WBR_checked]] id="checka5" onChange="this.form.submit();" /> <label for="checka5">Wood</label> </div> <p>Select Projection:</p> <div id="checkb"> <input type="checkbox" name="proj[]" value="5" [[+5_checked]] id="checkb5" onChange="this.form.submit();" /> <label for="checkb5">5"</label> <input type="checkbox" name="proj[]" value="9" [[+9_checked]] id="checkb9" onChange="this.form.submit();" /> <label for="checkb9">9"</label> <input type="checkbox" name="proj[]" value="12" [[+12_checked]] id="checkb12" onChange="this.form.submit();" /> <label for="checkb12">12"</label> </div> </form>
$output = "";
$path = MODX_CORE_PATH . 'components/aeibbproducts/';
$result = $modx->addPackage('aeibbproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$proj = array();
if (isset($_POST['proj']) && (! empty($_POST['proj']))) {
$proj = $_POST['proj'];
}
$group = array();
if (isset($_POST['group']) && (! empty($_POST['group']))) {
$group = $_POST['group'];
}
$checked = 'checked="checked"';
$c = $modx->newQuery('BbProducts');
$i = 0;
foreach($group as $selected) {
$condition = ($i) ? 'OR:' : '';
$c->where(array($condition.'pre:=' => $selected));
$i++;
$modx->setPlaceholder($selected . '_checked', $checked);
}
$j = 0;
foreach($proj as $select) {
$cond = ($j) ? 'OR:' : '';
$c->where(array($cond.'proj:LIKE' => $select.'%'));
$j++;
$modx->setPlaceholder($select . '_checked', $checked);
}
$total = $modx->getCount('BbProducts',$c);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$modx->setPlaceholder($totalVar,$total);
$modx->runSnippet('FeetInch');
$fi = new FeetInch($modx);
$noImage ='assets/media/jpgs/noimage-s.jpg';
$products = $modx->getCollection('BbProducts',$c);
foreach($products as $product) {
$fields = $product->toArray();
$width = $product->get('width');
$fields['nwW'] = 'Width: ' . $fi->dec2inch($width);
$height = $product->get('height');
$fields['nwH'] = 'Height: ' . $fi->dec2inch($height);
$proj = $product->get('proj');
$fields['nwP'] = 'Proj: ' . $fi->dec2inch($proj);
$pitch = $product->get('pitch');
$fields['nwPi'] = $pitch . ' Pitch';
$fleName = $product->get('aei');
$temp = 'assets/media/jpgs/prod-s/' . '01-' . $fleName . '.jpg';
$fields['imgLink'] = file_exists($temp) ? $temp : $noImage;
$output .= $modx->getChunk('showBrackets', $fields);
}
return $output;This question has been answered by BobRay. See the first response.
$i = 0;
$groupArray = array();
foreach($group as $selected) {
$condition = ($i) ? 'OR:' : '';
$groupArray[$condition.'pre:='] = $selected;
$i++;
$modx->setPlaceholder($selected . '_checked', $checked);
}
$j = 0;
$projArray = array();
foreach($proj as $select) {
$cond = ($j) ? 'OR:' : '';
$projArray[$cond.'proj:LIKE'] = $select.'%';
$j++;
$modx->setPlaceholder($select . '_checked', $checked);
}
$c->where(array($groupArray, $projArray));
That really looks like it should work. It may work to create the two arrays as separate arrays before creating the where() statementHi Bob,
$i = 0; $groupArray = array(); foreach($group as $selected) { $condition = ($i) ? 'OR:' : ''; $groupArray[$condition.'pre:='] = $selected; $i++; $modx->setPlaceholder($selected . '_checked', $checked); } $j = 0; $projArray = array(); foreach($proj as $select) { $cond = ($j) ? 'OR:' : ''; $projArray[$cond.'proj:LIKE'] = $select.'%'; $j++; $modx->setPlaceholder($select . '_checked', $checked); } $c->where(array($groupArray, $projArray));
) but now another problem appears: when I select a projection dimension first, I get an empty result. When I select a group first and then a proj dim, it works fine. When I switch the arrays in the where() statement (like below), selecting a group first gets an empty result.$c->where(array($projArray, $groupArray));

if ( (!empty($projArray)) && (!empty($groupArray)) ) {
$c->where(array($groupArray, $projArray));
} elseif (!empty($projArray)) {
$c->where(array($projArray));
} elseif (!empty($groupArray)) {
$c->where(array($groupArray));
}I can't believe that worked on the first try.This does the trick!! Thanks so much!
I don't see why it would be needed, but you might try this instead of line 19:
if ( (!empty($projArray)) && (!empty($groupArray)) ) { $c->where(array($groupArray, $projArray)); } elseif (!empty($projArray)) { $c->where(array($projArray)); } elseif (!empty($groupArray)) { $c->where(array($groupArray)); }
Wow, I hit the daily double.I'm sorry, but I celebrated too early!
I'm glad I could help.

$msg = "progArray" . print_r($progArray, true); $msg = "\ngroupArray" . print_r($groupArray, true); $modx->log(modX::LOG_LEVEL_ERROR, $msg);
Have you thought about leaving out all the onChange stuff and just putting a submit ("Search") buttons in the form? You could use multiple, identical submit buttons if you're worried about them scrolling off the page. I would think users would be annoyed by having the page reload every time they checked or unchecked a checkbox.Actually having the page reload every time a users checks a checkbox is kind of the idea on this page. The user starts with ~2000 products and can whittle it down to their choice(s) by checking off a group or groups and a dimension or dimensions.
I'm not sure that would solve your problem, but it might.
As a diagnostic, I would try adding this code near the end:I can only get this code to work for one of the arrays at the time but nevertheless it shows what's happening:
$msg = "progArray" . print_r($progArray, true); $msg = "\ngroupArray" . print_r($groupArray, true); $modx->log(modX::LOG_LEVEL_ERROR, $msg);
That should let you look at the content of the two arrays in the error log. If you install the controlErrorLog extra, you can just click on the triangle at the top right of the menu to see the results.
[2015-12-21 16:07:17] (ERROR @ /index.php)
projArrayArray
(
)
[2015-12-21 16:07:45] (ERROR @ /index.php)
projArrayArray
(
[proj:LIKE] => 13.%
)
[2015-12-21 16:07:47] (ERROR @ /index.php)
projArrayArray
(
[proj:LIKE] => 13.%
[OR:proj:LIKE] => 14.%
)
[2015-12-21 16:07:50] (ERROR @ /index.php)
projArrayArray
(
[proj:LIKE] => 13.%
[OR:proj:LIKE] => 15.%
)