splitting a set of list results

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

Re: [zaba] splitting a set of list results

By (Deleted User) - April 5, 2012

Hi Zaba,

If you want to split up the records returned from a getRecords call, you can do this:
// Loop over the records
<?php foreach $records as $key=>$record : ?>
<?php if ( $key == 0 ) : ?>
<!-- Output the first record using specific html/css -->
<?php elseif ( $key == 1 ) : ?>
<!-- Output the second record using specific html/css -->
<?php elseif ( $key == 2 ) : ?>
<!-- Output the third record using specific html/css -->
<?php elseif ( $key == 3 ) : ?>
<!-- Output the fourth record using specific html/css -->
<?php elseif ( $key == 4 ) : ?>
<!-- Output the fifth record using specific html/css -->
<?php elseif ( $key == 5 ) : ?>
<!-- Output the sixth record using specific html/css -->
<?php endif; ?>
<?php endforeach; ?>


In each of the "if" statements you're checking to see what record is being looked at - assuming you have set the order in CMSB you can then simply output the content of the record array as desired with unique html/css for each record.

This is a very simply method and not terribly graceful, but once you get it working this way you can start to refine it.

Let me know if this helps,

Tom

Re: [Tom P] splitting a set of list results

By zaba - April 10, 2012

Thanks Tom,
Perfect!!

oh, theres a little error in your code in case anyone else needs to use it

// Loop over the records
<?php foreach $records as $key=>$record : ?>

replace with below (just some brackets missing..)

// Loop over the records
<?php foreach ($records as $key=>$record) : ?>