Re: [concrete] Mulit Select Dropdown search
Hi concrete,
CMS Builder's automatic searching features don't support multi-value fields or "OR" searches yet.
You can do it with some custom PHP and a MySQL 'where' though. Here's how:
Create a multi-select like northernpenguin showed:
<select name="myMultiSearch[]" multiple="multiple" size="4">
<option>value 1</option>
<option>value 2</option>
<option>value 3</option>
</select><br/>
The key parts are:
- HTML needs multiple="multiple" to allow multiple values
- PHP needs [] on the end of the fieldname to receive multiple values
- The size="4" indicates the height in rows of the select box.
Next, you need to loop over those values in your PHP and generate some MySQL. Here's the code for that:
// create multi field where
$where = '';
if (@$_REQUEST['myMultiSearch']) {
$where = "0";
foreach ($_REQUEST['myMultiSearch'] as $value) {
$where .= mysql_escapef(" OR `cmsfield` = ? ", $value);
}
$where = "($where)";
}
What this code does is create a where like this: (0 OR `cmsfield` = 'value 2' OR `cmsfield` = 'value 3' )
Make sure to rename 'cmsfield' to the field you want searched.
Finally, pass this code to getRecords() with this option:
'where' => $where,
Also, be prepared to spend a little time experimenting to get this working correctly. Preparing for that upfront can save a lot of frustration.
Hope that helps!
Dave Edis - Senior Developer
interactivetools.com