Working with ‘join’ code

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 13, 2016   (RSS)

Hi All,

I’ve created a list page that shows the all the checked value labels in a list field for all user accounts (members).

I’m not sure how to exclude those records with only one value checked from my list page.

Here’s the simple code that I’m currently using with a comment in red to show what I’m looking for:

 <table class="text_font" width="100%" border="1"  cellspacing="0">
  <tr>
    <td style="padding-left:10px;">Last Name</td>
    <td style="padding-left:10px;">First Name</td>
    <td style="padding-left:10px;" colspan="3">Assignments</td>
   
  </tr>
 

<?php foreach ($accountsRecords as $record ): ?>
       <?php if ($record['allowedFolders'] ): // && $record['allowedFolders'] has more than one value ?>
     
      <tr>
    <td style="padding-left:10px;"><?php echo $record['last_name'] ?></td>
    <td style="padding-left:10px;"><?php echo $record['first_name'] ?></td>
    <td style="padding-left:10px;"><?php echo join(', ', $record['allowedFolders:labels']);?></td>
    
  </tr>
       <?php endif?>
          <?php endforeach; ?>
       </table>

Thanks as always,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - April 13, 2016

Hi Jerry,

Here is one way to do it:

<table class="text_font" width="100%" border="1"  cellspacing="0">
          <tr>
            <td style="padding-left:10px;">Last Name</td>
            <td style="padding-left:10px;">First Name</td>
            <td style="padding-left:10px;" colspan="3">Assignments</td>
          </tr>
    <?php foreach ($accountsRecords as $record ): ?>
       <?php if(substr_count($record['allowedFolders'], "\t") > 2): ?>
          <tr>
            <td style="padding-left:10px;"><?php echo $record['last_name'] ?></td>
            <td style="padding-left:10px;"><?php echo $record['first_name'] ?></td>
            <td style="padding-left:10px;"><?php echo join(', ', $record['allowedFolders:labels']);?></td>
         </tr>
       <?php endif?>
    <?php endforeach; ?>
</table>


Counting the tab spaces in the allowedFolders string. One value equals two tab spaces so I added the more than 2 condition.

Try this out and let me know if this gives you the results you are after.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/