splitting a set of list results

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

By zaba - April 5, 2012

Hi, I am wanting to split a set of returned results from a db table of 6 returned results, rather than return the results with all the same formatting applied, I want to apply different formatting to each of the returned results. So say for example the first result in the list may have a larger image and larger heading, results 2 and 3 will be smaller and floated to the right of it. Results 4 and 5 will be smaller boxes on top of each other and result 6 will be as result 1 and floated to the right.
This is not a css thing as I can easily build the divs in a fixed layout and assign use thumb 1 or 2 for the different sizes. Its just how do I pull each individual record from a list in order to then assign it to its div formatting. There will be a max of 6 records, each containing an image and heading. The order will be controlled by the cms order dragging mechanism so they would be able to poppulate the grid in the order they have entered them in the cms. To visually explain ive attached a layout. As I say this is not a css layout issue its purely how to break out the code into the individual divs. Any help would be greatly appreciated.
Attachments:

picture-40.png 231K

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