List field options from another section
3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2017 (RSS)
By andreasml - June 18, 2017
Hi all,
In the Section A of my CMSB, a list-type field gets its options from another section (Section B). Section B contains three different fields (ex. title, content, description). I would like this particular list field of Section A to contain two fields from Section B (ex title, content). Please note that I am interested in the cmsb control panel for the input of information and not for the listing or detail pages.
I have used the following MySQL code for the list options of this particular list field of the Section A.
SELECT title, content
FROM `<?php echo $TABLE_PREFIX ?>section_b`
ORDER BY title
Nevertheless, the list options of this field of Section A returns only the "content" field from Section B, and not both "title" and "content" fields as I expected.
Any help provided would be much appreciated. Thanks in advance.
Andreas Lazaris, Athens Greece
Level: beginner
By Dave - June 18, 2017
Hi andreasml,
The CMS doesn't support that directly, but you can do it with custom MySQL code. It's a bit more advanced but give this a try:
SELECT num, CONCAT(title, ': ', content)
FROM `<?php echo $TABLE_PREFIX ?>section_b`
ORDER BY title
The first field is what is stored in the database, the second is what is shown to the user. The reason we usually want to store a record number in the database is so if the title or content changes we can still find it by record number.
The MySQL CONCAT function joins multiple values together.
Reference: https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat
Hope that helps!
interactivetools.com