Re: [NigelGordijk] Populating a dropdown menu via CMSB
Hi,
Sure, if you set up a section in the CMS to store a list of store names, you can use that list to dynamically populate a select box.
In this example, we're assuming that the section is called "stores".
First we select all the stores from the database. We also select which fields we want to use as the options values and labels. in this example, we use "num" and "title", but these can be changed to whatever you want:
<?php
$query = "SELECT * FROM `{$TABLE_PREFIX}stores`";
$stores = mysql_query_fetch_all_assoc($query);
$valueField = "num";
$labelField = "title";
?>
Then we output your select box:
<select id="Store Name" class="select480" name="Store Name">
<option value = "">Please Select...</option>
<?php foreach ($stores as $store): ?>
<option value = "<?php echo $store[$valueField];?>" <?php selectedIf($store[$valueField], @$_REQUEST['Store Name']);?>><?php echo $store[$labelField];?></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/