Populating search form from database

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="">&lt;select&gt;</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

Greg Thomas







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