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 RGC - February 6, 2013 - edited: February 6, 2013

I am looking for code to display the values from a list field (field name - county) which is a field within a multi record (table name - towns)

If I use the following code the value displays repeatedly for every mutli-record that is associated with it. I only want to display the county once.

          <?php
              // load records from 'towns'
              list($townsRecords, $townsMetaData) = getRecords(array(
                'tableName'   => 'towns',
                'loadUploads' => true,
                'allowSearch' => false,
              ));
            
            ?>
          <?php foreach ($townsRecords as $record): ?>
          <li><?php echo $record['county'] ?></li>
          <?php endforeach ?>

Thanks for you assistance!

Rod

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