Fill dropdown list from database table

gvannauw 04 Nov, 2022
Hi everyone
I have a table called 'Clubs' in the database. This contains one column called 'Club' which currently contains 3 entries, namely 'Pegasus', 'Apollo Flyers', 'Albatros modelvliegclub'
There will be more clubnames in the future, but for testing purposes, I only used three.
I created a dropdown table, connected it to the database table and used vml as alias for the table.
Then I used option value {var:vml.Club} to generate the dropdown list.
When I look at the result in the administrator section, I can see that the list seems to contain three fields (since I can move the cursor up and down three times), but none of the names of the clubs show in the dropdown.

What am I doing wrong please?

Tks + best regards
Gino
GreyHead 04 Nov, 2022
Hi Gino,

I suspect that your dropdown requires entries for both the displayed text and the value and you are only providing the value.

Bob
gvannauw 04 Nov, 2022
Hi Bob
So how can this be solved? My table contains one column only, namely the name of the club. The options table indeed presents me with two options , i.e. options value and options text.
Does this mean I have to change the layout of the table clubs and if so, what needs to be adjusted? Do I need to create a primary key?

Tks for your kind assistance
Gino
GreyHead 05 Nov, 2022
Hi Gino,

The simplest way is probably to use the record id from the table as the value. If the names are simple you could possibly use the name as both the value and the text.

Bob
gvannauw 06 Nov, 2022
ok Bob
I have now altered the table with following fields
id <- primary key - auto increment
club <- text field - 25 long
info <- text field - 20 long

When connecting the read data attribute I used (obviously) the source table which is #_clubs and used as model name club
I opted in the select to 'all matching records'

Then in the views editor I connected the data source namely
form.start_page - Read Data 2
And in the option data I have set

Option Value {var:club.id} and
Option Text {var:club.club}

When running the administrative view, I only see the first entry in the table, names of all the other clubs are not present ..

Clearly, stupid me, I am doing something wrong along the way, but I simply can't figure it out.
I was of the opinion that when selecting the option 'all matching records' the array (model name) would be filled, but no way ???

Sorry for my ignorance😟
gvannauw 06 Nov, 2022
sorry .. it gave me the last record of the table .. all others were not present in the dropdown list .. my mistake
gvannauw 06 Nov, 2022
Answer
got it

specified options as follows

Option value : {var:clubs.id}
option value : {var:clubs.club}
option text : {var:clubs.club}

Now all appear in the dropdown list

Tks for the assistance🙂
You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger