Re: [4cdg] Search from multiple fields in form
Hi Clay,
This one is a little more complicated since msba_region is associated with a user and not with a listing.
The first thing you'll need to do in on search.php. You'll need to create a list of all the possible regions from the accounts table like this:
*Note* put this below the query where we select all the user accounts
$regions = array();
foreach($accountRecords as $account){
if($account['msba_region']){
$regions[$account['msba_region']]=$account['msba_region:label'];
}
}
Next, you can output this into your drop down menu for selecting a region. Like this:
<select name="searchRegion">
<option value="">-SELECT-</option>
<?php foreach($regions as $value => $label):?>
<option value="<?php echo $value;?>"><?php echo $label;?></option>
<?php endforeach ?>
</select>
Since we can't get the search for this to happen automatically, we'll need to add some code to our search results page:
Put this BEFORE your getRecords statement on the search results page:
$andWhere = "1";
if(@$_REQUEST['searchRegion']){
$query = "SELECT * FROM `{$TABLE_PREFIX}accounts` WHERE msba_region='".mysql_escape($_REQUEST['searchRegion'])."'";
$users = mysql_query_fetch_all_assoc($query);
$userNums = join(",",array_pluck($users,'num'));
if($userNums){
$andWhere.=" AND createdByUserNum IN($userNums)";
}
}
This selects all the user numbers that have the selected region and ads them to a variable that we can put into our getRecords Query.
Finally, add this to the getRecords query on the search results page:
'where' => $andWhere,
This should take care of it. Give it a try and if you run into any issues, attach search.php and your search results page to this thread so I can take a look at your code.
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/