Populate drop down search form field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 6, 2010   (RSS)

Re: [darrylo] Populate drop down search form field

By Jason - November 4, 2010

Hi Darrylo,

What you can do is use 2 foreach loops. The first one would be used to create an array of cities like this:

<?php
$cities = array();
foreach ($listingsRecords as $record){
$cities[$record['city']]=$record['city'];
}
?>

Any duplicates will overwrite each other, so you'll only every have one of each city. Next, you just need to output your cities like this:

<select name="city">
<option value="">Any Town</option>

<?php foreach($cities as $city): ?>
<option value="<?php echo $city;?>"><?php echo $city;?></option>
<?php endforeach?>
</select>


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/

Re: [Jason] Populate drop down search form field

By darrylo - November 6, 2010

Awesome - you're the man Jason - Thank you!
Darryl
http://darrylo.com