Home | Products | Consulting | Forums | Support | Order | 1-800-752-0455
  Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Populate a dropmenu with database values

 

 


ryan_dot
User

Nov 18, 2008, 2:33 PM

Post #1 of 4 (557 views)
Shortcut
Populate a dropmenu with database values Can't Post

Hi Folks,

I have a table called 'cars' in my database with a list menu field called 'make'. I want to create a dropdown menu on the website that will allow users to select from the all values from this 'make' field. Is this possible?

I want to use it as part of a search feature for filtering search results.

Thanks


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie


bruno
User

Nov 18, 2008, 6:42 PM

Post #2 of 4 (547 views)
Shortcut
Re: [ryan_dot] Populate a dropmenu with database values [In reply to] Can't Post

I'm trying to do the same thing. This post might help...

http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Populate_a_dropmenu_with_database_values_P66987/gforum.cgi?post=60625;search_string=mysql%20pull%20in%20table%20to%20drop%20down;guest=31001062&t=search_engine#60625


(This post was edited by bruno on Nov 18, 2008, 6:43 PM)


Dave
Staff / Moderator


Nov 19, 2008, 2:31 PM

Post #3 of 4 (532 views)
Shortcut
Re: [ryan_dot] Populate a dropmenu with database values [In reply to] Can't Post

Hi Ryan,

Try something like this:


Code
<?php 
// get field options
$tablename = 'widgets';
$fieldname = 'color';
$selectedValue = '';
$valuesAndLabels = getListOptions($tablename, $fieldname);
$optionsHTML = getSelectOptions($selectedValue, array_keys($valuesAndLabels), array_values($valuesAndLabels));
?>

Widgets Colors:

<select name="color">
<?php echo $optionsHTML ?>
</select>


Hope that helps!

Dave Edis - Senior Developer
interactivetools.com


ryan_dot
User

Nov 19, 2008, 3:33 PM

Post #4 of 4 (530 views)
Shortcut
Re: [Dave] Populate a dropmenu with database values [In reply to] Can't Post

Hi Dave, i must try that the next time, it looks more efficient than what i ended up doing.

I ended up creating a seperate table for the 'make' and linked it to the cars table and used this code to create a drop down menu for the search feature.

<select name="make" class="dropdown" id="make" >
<option value="">Any</option>
<?php foreach ($makeRecords as $record): ?>
<option value="<?php echo $record['make'] ?>"><?php echo $record['make'] ?></option>
<?php endforeach; ?>
</select>

It works fine for me, and since there is now a table for 'make' it allows the site owner to add new makes to the database and it automatically updates the search menu.

Thanks


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie

 
 
 


Search for (options)
Products
CMS Builder
Article Manager
Realty Manager
Listings Manager
Order Now
Services
Priority Consulting
Support
Online Documentation
Support Forums
Support Homepage
Company Info
12 reasons to choose us!
Meet the team
Monthly newsletter
Contact Us
Toll Free: 1-800-752-0455
Phone: (604) 689-3347
Sales | Support
Conditions of Use | Privacy Policy | Copyright © interactivetools.com 2008
#201 - 2730 Commercial Drive, Vancouver BC Canada V5N 5P4