I have a standard code to search by column and am now trying to add the option of searching multiple criteria in one column. Currently I can search by one criteria, so if the user selects location QLD it will display all QLD entries, what changes do i need to make to enable the user to search both for location QLD and NSW?
I have updated the element to be multiple, but am not sure how to adjust the PHP and MySQL to process multiple criteria.
Can someone help?
Thanks, sbgmedia
<?php
$condition = '';
if(isset($_REQUEST['Location']) and $_REQUEST['Location']!=""){
$condition .= ' AND Location LIKE "%'.$_REQUEST['Location'].'%" ';
}
$userData = $db->getAllRecords('candidates','*',$condition,'ORDER BY id ASC');
?>
<select name="Location[]" id="Location" class="form-control" value="<?php echo isset($_REQUEST['Location'])?$_REQUEST['Location']:''?>" multiple>
<option value="" <?php if(isset($_REQUEST['Location']) && $_REQUEST['Location'] == '')
echo ' selected="selected"';?></option>
<option value="ACT" <?php if(isset($_REQUEST['Location']) && $_REQUEST['Location'] == 'ACT')
echo ' selected="selected"';?>ACT</option>
<option value="NSW" <?php if(isset($_REQUEST['Location']) && $_REQUEST['Location'] == 'NSW')
echo ' selected="selected"';?>NSW</option>
<option value="QLD" <?php if(isset($_REQUEST['Location']) && $_REQUEST['Location'] == 'QLD')
echo ' selected="selected"';?>QLD</option>
</select>
mysqliand PDO where any user-supplied data is specified with a?or:nameindicator that’s later populated usingbind_paramorexecutedepending on which one you’re using.getAllRecords()?Location IN (...)or expand to a series ofx LIKE yjoined byOR. You can also crunch them down into a single regular expression forRLIKE.