Page 1 of 1
Select multi - show descriptions
Posted: Thu Mar 29, 2018 5:14 am
by Timo
A select object with multiple = YES, that uses a sql, stores the selected values in an array format like ["3","1","4""]. The browse form also shows the numeric values. How do I show the string values instead?
currently this is shown in the browse form:
["3","1","4""]
this should be shown instead (descriptions with commas separated)
items 3, item 1, item 4
Is there an easy way to accomplish this?
Re: Select multi - show descriptions
Posted: Fri Mar 30, 2018 12:54 am
by admin
Timo,
How many columns does your SQL statement return?
Steven
Re: Select multi - show descriptions
Posted: Fri Mar 30, 2018 5:58 am
by Timo
The lookup sql return just two column and look like this
Code: Select all
SELECT
ident, description
FROM
table
ident is numeric (1,2,3,4) and the description is a varchar
Re: Select multi - show descriptions
Posted: Fri Mar 30, 2018 6:47 am
by admin
Timo,
I don't get what you are saying.
Can you rephrase it?
Steven
Re: Select multi - show descriptions
Posted: Fri Mar 30, 2018 9:00 am
by Timo
Let me repeat by adding some screenshots: I got an object of Type: Select on my form. Multiple is set to Yes.
Its SQL looks like this:
Then I select multiple items form the select object, save the record. In the database it looks like this:
table_main.PNG
In the browse view it looks like this too:
browse_view.PNG
But it should look like this, showing the reasons and not the ident
reasons_desc.PNG
Is this more clear?
Re: Select multi - show descriptions
Posted: Fri Mar 30, 2018 10:07 am
by admin
Timo,
Thanks.
In a Select Object it is whatever is in the first column that gets saved.
So you could try
Code: Select all
SELECT
reason as a, reason as b
FROM
table
Steven
Re: Select multi - show descriptions
Posted: Sun Apr 01, 2018 4:21 am
by Timo
Yeah, that's how it's gonna work. Although, I was just trying to stick to normalization rules and was hoping for a better solution.
Re: Select multi - show descriptions
Posted: Sun Apr 01, 2018 5:24 am
by admin
.
Re: Select multi - show descriptions
Posted: Sun Apr 01, 2018 10:14 am
by Timo
Found a solution with INNER JOIN and FIND_IN_SET.
The idea is taken from
https://stackoverflow.com/questions/191 ... s/19101646
Code: Select all
SELECT a.nid,
GROUP_CONCAT(b.name ORDER BY b.id) DepartmentName
FROM Notes a
INNER JOIN Positions b
ON FIND_IN_SET(b.id, replace(replace(replace(a.forDepts,'[',''),']',''),'"','')) > 0
GROUP BY a.nid
Re: Select multi - show descriptions
Posted: Sun Apr 01, 2018 8:49 pm
by admin
.