How to display multi-value checkbox comma seperated or CSS

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 9, 2014   (RSS)

By gregThomas - July 25, 2014

Hi Andy,

If you're using the getRecords function to retrieve the record, it will come with an array of all of the selected labels for that field. You could loop through it like this:

<?php $lastIndex = count($listing['features:labels']) - 1; ?>

<?php foreach($listing['features:labels'] as $key => $label): ?>
  <?php echo $label; ?><?php if($key != $lastIndex): ?>, <?php endif; ?>
<?php endforeach; ?>

So the above code loops through the labels array, it will then display each items label, and add a comma at the end if we're not dealing with the last item.

You just need to amend the above code to work with the HTML in your previous post.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By andybarn - July 27, 2014

Hi Greg

Thanks for your reply. I managed to achieve what I wanted doing it a different way using the php echo join command.

Below is my code

                <div class="headline"><h3>Property Features</h3></div>
                <i class="fa fa-check-square-1st"></i><?php echo join('<i class="fa fa-check-square-o"></i>',$listing['features:values']); ?><br/>

The class

<i class="fa fa-check-square-1st"></i>

creates the first tick box and the following code below

<?php echo join('<i class="fa fa-check-square-o"></i>',$listing['features:values']); ?>

uses the css code (which creates the other tick boxes) instead of a comma which is normally used the the comma separated list of features.

As I say, this works for me, though probably not as elegant as your suggested code.

Thanks for looking into this for me.

Andy

By andybarn - August 9, 2014

Hi Greg

Just a quick update.

I was finding my code a bit limiting, so reverted back to your code which was far more flexible.

Your code worked straight away and with a little modification,  I managed to achieve exactly what I wanted.

Thanks very much again for your help.

Kind Regards

Andy