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 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