Separate List Output with Comma

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 2, 2018   (RSS)

By mark99 - November 2, 2018

One of my fields is a selection list and when I output it using this:

<?php echo $record['test'] ?>

I get this:

TEST1 TEST2 TEST3

But what I want is this:

TEST1, TEST2, TEST3

What's the best way to add the comma, albeit not on the final output item (e.g. TEST3 above as I don't want a comma on the very end of the line)?

By daniel - November 2, 2018

Hi mark99,

If you are using getRecords() to retrieve your record, you should be able to use the following:

<?php echo implode( ', ', $record['test:labels'] ); ?>

If you used a different method to access the record or "test:labels" is otherwise unavailable, this alternate method should also work:

<?php echo implode( ', ', listValues_unpack( $record['test'] )); ?>

Let me know if I can help with anything else!

Thanks,

Daniel
Technical Lead
interactivetools.com

By mark99 - November 2, 2018

I figure out I can also do it with this, but which approach is better (yours or mine)?

<?php echo join(', ', getListLabels('isp_list', 'sfbb_broadband_type_premium', $isp_listRecord['sfbb_broadband_type_premium'])); ?>