It seems like a simple thing and yet I cannot get it to work - stored array back into single select or list dropdown

Although it was a bit of a learning curve, it turns out saving data into a table field as a comma delimited array works well and making choices of that array in a multi-select in a form also works well… but I cannot seem to fathom how to bring that stored array (text serial numbers) back onto a page as either a non-multi-select or even as a list dropdown. The field where the data is stored is good, and I can get a double row of both stored serial numbers: PB0004-10001,PB0004-10002 and even though I am using split, I am getting this in the select (the choice is meant to trigger a goto that does work):

Capture

The code looks like this:


The conn_units.data.getSerials_user is a query that filters the database to a single user by logged-in identity and shows that specific array field, if a general query is needed that would be conn_units.data.getSerials and it would show ALL stored serial numbers before any filtering (this was needed when creating the original insert). This is all in a form but it does not get submitted… the select items all use a dmx-on:changed="browser1.goto - I tried using a $_GET and the same thing is showing, the proper rows count of two items but both show both array items.

There are many lessons on adding data into an array, but maybe a quick detailed lesson on bringing that array back onto a page or into a select as an item to choose from (not as an update) please? This is a 30-second job if just bringing in a regular database query but the split has had me flummoxed for 2 days now.

Your split needs to be on the data source not the text/value settings

dmx-bind:options="conn_units.data.getSerials.split(',')"

Then just use $value in the optionvalue and optiontext bits
e.g. optionvalue="$value" optiontext="$value"

If you paste your select as code rather than a screenshot, people can use it as a basis to help.

update
You could use a ternary expression if the user query has values then use that, otherwise use the other query:

dmx-bind:options="conn_units.data.getSerials_user.UNITS.split(',').hasItems() ? conn_units.data.getSerials_user.UNITS.split(',') : conn_units.data.getSerials.split(',')" optionvalue="$value" optiontext="$value"

p.s. welcome to the community!

Thank you for the welcome. I indeed pasted the code and it shows in my editing version but not in the live version (maybe I’ll try the preformatted button etc.). I will check that out and also try the fix you provided. If all goes well I will reply with the details of the eventual solution for me.

This worked perfectly:

<select name="listUnits" id="listUnits" dmx-bind:options="conn_units.data.getSerials_user.UNITS.split(',').hasItems() ? conn_units.data.getSerials_user.UNITS.split(',') : conn_units.data.getSerials.split(',')" optiontext="$value" optionvalue="$value" dmx-on:changed="browser1.goto('admin_detail.php?sn='+selectedValue)">

              <option value="null">Select a Unit to View Current Data</option>

            </select>