Populating search form from database
3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 10, 2013 (RSS)
By andybarn - April 9, 2013
Hi
I am using the Basic Realty plugin
On the search.php file that comes with package, the search form pulldowns are hard coded with the select options.
I want to pull these in dynamically from the cmsAdmin property_type field
For example, the property_type pulldown is as follows
<td>
<select name="property_type">
<option value=""><select></option>
<option value="">Any</option>
<option>Home</option>
<option>Condo</option>
<option>Townhouse</option>
<option>Apartment</option>
<option>Mobile Home</option>
<option>Lot</option>
<option>Acreage</option>
<option>Duplex</option>
<option>Triplex</option>
<option>Farm or Ranch</option>
<option>Other</option>
</select>
</td>
Please could you provide an example of the code required to populate the property_type pulldown dynamically from the database. Please use the standard form as an example so I can see how this works and then will be able to apply the code to the other pulldowns.
Thanks for your help.
Kind Regards
Andy
By gregThomas - April 10, 2013 - edited: April 10, 2013
Hi,
You could use getListOptions function to retrieve them from the database, something like this should work:
$options = getListOptions('listings', 'property_type');
?>
<td>
<select name="property_type">
<option value=""><select></option>
<option value="">Any</option>
<?php foreach($options as $value => $label): ?>
<option value="<?php echo $value; ?>" ><?php echo $label; ?></option>
<?php endforeach; ?>
</select>
</td>
The getListOptions function returns an array of list options, the two variables required for it are the table and field name.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com
By andybarn - April 10, 2013
Hi Greg
Great that did the trick - thanks very much - works just how I want it!!
Just to point out for anyone else though, you missed the opening "<?php" from the start of your code - should read
<?php $options = getListOptions('listings', 'property_type'); ?>
Thanks again - great support and product
Andy