Display Values from List Field Type in a Multi Record

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 6, 2013   (RSS)

By Steve99 - February 6, 2013

Hello,

You can use this code as a base to work from:

<?php $memos_grouping = array_filter(array_pluck($memosRecords, 'group')); ?>
<?php foreach ($memos_grouping as $memos_group_name): ?>
  <p><strong><?php echo $memos_group_name; ?></strong></p>
  <ul>
  <?php foreach ($memosRecords as $record): ?>
  <?php if ($record['group:label'] == $memos_group_name) : ?>
    <li><?php foreach ($record['file_upload'] as $upload): ?><a href="<?php echo $upload['urlPath'] ?>" target="_blank"><?php echo $record['title'] ?></a><?php endforeach ?></li>
  <?php endif ?>
<?php endforeach ?>
  </ul>
<?php endforeach ?>

This takes the items from a list field and displays it once with all correlating records displayed beneath. I happened to be displaying an upload in this scenario.

Hope this helps.

By RGC - February 6, 2013

Thanks Steve I have taken your code and re-written as follows:

<?php $towns_grouping = array_filter(array_pluck($townsRecords, 'county')); ?>
<?php foreach ($towns_grouping as $towns_group_name): ?>
  <p><strong><?php echo $towns_group_name; ?></strong></p>

<?php endforeach ?>

The county values are displaying, but repeatedly for each multi record associated with the county list value. What I am looking to do is just display the 8 values for the list type county once.

Rod

By Steve99 - February 6, 2013

You need that other chunk of code in there. Just swap out "FIELD" with your field name.

  <?php $towns_grouping = array_filter(array_pluck($townsRecords, 'county')); ?>
  <?php foreach ($towns_grouping as $towns_group_name): ?> 
  <p><strong><?php echo $towns_group_name; ?></strong></p>

  <ul>
   <?php foreach ($townsRecords as $record): ?>
   <?php if ($record['county:label'] == $towns_group_name) : ?>    
     <li><?php echo $record['FIELD'] ?></li>
   <?php endif ?>
   <?php endforeach ?>
  </ul>

  <?php endforeach ?>

Let me know how that works out for you.

Output should be:

Town Group Name 1
- correlating records

Town Group Name 2
- correlating records

Town Group Name 3
- correlating records