Pulldown Fields - Value vs. Label

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 21, 2008   (RSS)

By InHouse - August 20, 2008 - edited: August 21, 2008

I have a question about how CMSB stores info collected through a pulldown field.

Right now my menu field is populated from another table. It uses the record number for the value and a text field (title) as the displayed label.

When I look a the CMSB list of records, it appears to be storing the label string in the database rather than the expected record number. Have not yet checked the actual MySQL info.

When I display this info on a page, the expected shows up - the value (record number) and not the string. Good so far... but I actually would like to show the label text in this one instance rather than the record number. Since CMSB appears to be storing that anyway, is there a way that I can resolve to the stored label rather than create a secondary lookup for each displayed record?

If not, can you suggest an efficient lookup loop to handle this?

Many thanks,
J.

Re: [InHouse] Pulldown Fields - Value vs. Lable

By Dave - August 20, 2008

Hi J,

There's no elegant built in way to do this yet. I think in future we may add pseudo fields that let you refer to either value as: fieldname:label or fieldname:value.

It is stored in the database as a value, and a label is shown in many cases on the backend as that's usually when people want (except when they don't!). :)

Anyways, here's some code to get the label from the value.

<?php
$tableName = 'news';
$fieldName = 'related';
$fieldValue = $newsRecord['related'];
$labelArray = getListLabels($tableName, $fieldName, "\t$fieldValue\t");
$label = @$labelArray[0];
?>

Just replace the variable name with your own and then use $label where you want the label to appear.

Let me know if this works for you.
Dave Edis - Senior Developer
interactivetools.com