Forums

Dynamic Dropdowns

kavaXtreme 17 Sep, 2008
It took my a while to figure this out, so I thought I'd post it here in case someone else found it useful. It's really pretty simple, but those of us who only read a little php need all the help we can get.

If you want to create a dropdown that is populated with records from a table in your database, modify this code to your needs and put it in Form Code->Form HTML:

<?php
$sql ="select DISTINCT your_field_name from jos_your_table_name order by your_field_name ASC";
$database->setQuery($sql);
$rows = $database->loadObjectList();
foreach ($rows as $row) {
  $selectOptions .= "<option value=\"$row->your_field_name\">$row->your_field_name</option>";
}
?>

<select>
  <option value="">Any</option>
  <?php echo $selectOptions ?>
</select>


Oh, and here's the link to the famous "sofia's property listings" thread if you were looking for that, or just want to take this concept to another level (including AJAX thanks to Max): http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=6838&start=0&st=0&sk=t&sd=a&hilit=sofia
Max_admin 18 Sep, 2008
Thanks for sharing this, I will move it to the "suggestions/hacks" forums!🙂

regards

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.