How to load a dropdown value from a database

peterswa62 28 Sep, 2012
I have an enum column in my database table called title with these values:- Mr,Mrs,Ms,Miss, Dr

When I load a form for editing I need the person's title to show on a drop down with the correct one saved in the database whilst allowing it to be changed.

I can figure out how to show values in the options of the drop down but how do I show the one saved in the database?
GreyHead 29 Sep, 2012
Hi peterswa62,

I'm, not quite sure what your question is here? If you are editing a saved record then I think that loading it with the DB Record Loader will set the value correctly. If it's a new record then there should be no problem provided that the option values in your form Select drop-down element match the enum list in the database table.

Bob
peterswa62 29 Sep, 2012
Thanks for the reply. Yes I want to edit a saved record. I know how to load in values from a record in the table such as varchars using DB Record Loader, but am having trouble with enums. There are 3 settings on the Advanced Settings tab:- Array Field Sets, Array Separators and Parameter Fields. Do you have to set these to something to load in the value of an enum field?
Max_admin 29 Sep, 2012
Hmm, so your enum column has "Dr" for example ? or has the whole list ? if its has "Dr" and your form field name is "title" then "Dr" should be selected in the dropdown.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
peterswa62 30 Sep, 2012
The problem is the record when shown from loading from the database shows Mr when it should show Ms. In fact it shoes Mr for all records. How do I get it so the drop down is set to the saved value in the database?
peterswa62 30 Sep, 2012
I want to show a saved record from a database for editing. Using DB Record Loader I understand how to load values from varchar fields by using the Model ID but not how to show a saved value from an enum field. I have a drop down with values which correspond to values in the enum field in the database. But how do you set the value in the drop down so it is the same as the one saved in the database?
GreyHead 01 Oct, 2012
Hi peterswa62,

I built a test form to save the title to an ENUM column in a table and the save and republish work with no problem.

I created the table with an ENUM('Mr','Mrs','Ms','Miss','Dr') column named 'title' and the matching dropdown in the form also named 'title' and with the options
Mr=Mr
Mrs=Mrs
Ms=Ms
Miss=Miss
Dr=Dr

Bob
This topic is locked and no more replies can be posted.