breaking up results into varying columns

8 posts by 2 authors in: Forums > CMS Builder
Last Post: March 21, 2012   (RSS)

By zaba - March 20, 2012 - edited: March 20, 2012

Hi I am trying to achieve a brickwork pattern to display results, the results will need to split into rows, each "brick" (result) will be enclosed in a div and I want them layed out so the first row contains 3 bricks centred and the second row 2 bricks centred and the 3rd row 3 bricks and the fourth row 2 bricks and so on. I can't think of how I would go about this. I have no problem with doing the css, if it were a static layout, its just how to divide it all up so it does this dynamically.
Hope this makes sense, if you need any more info please let me know. see picture for layout.
Attachments:

picture-26.jpg 58K

Re: [zaba] breaking up results into varying columns

By (Deleted User) - March 20, 2012

Hi zaba,

Unfortunately we're not really designers and your question is more of a general html/css question than one to do with CMSB.

Having said that, my recommendation would be to use the styling elemnt 'float:left' for the cells with a counter in php to check how many cells have been drawn and how many rows (using a foreach loop and two variables like $rows and $cells).

Each row should then be in it's own div with the width fixed to be the combined width of the number of cells in that row, centered with margins (margin: 5px auto;).

The whole layout should be in a container div of fixed width to ensure that it all sits correctly relative to each other and then does not adversely affect the surrounding elements (with an element such as "<div style='clear:both;'></div>" as the last thing before closing the container div for the brick pattern).

So to recap, we're not designers, but if you want us to look at the code you've created to do the above we could always make suggestions.

Hope this helps,

Tom

Re: [Tom P] breaking up results into varying columns

By zaba - March 20, 2012

I think you misunderstood me. I can do all the css but the bricks would be generated dynamically, how can I split up the results say from 50 entries so that it pulls in 3 then 2 then 3 then 2 as the style for a brick on the first row would be different from the style of the css brick on the second row and it would alternate.

Re: [Tom P] breaking up results into varying columns

By zaba - March 20, 2012

Thanks Tom,
I think I should be able to follow that, theres another element to this though.which i didnt mention, i need to also limit the results into blocks of 13 results.
So if there are 52 results I need to build the bricks in rows of 3 and 2 for 5 rows (=13 blocks) and then close the enclosing div before starting the process again on the next div block if you get my drift.

Re: [zaba] breaking up results into varying columns

By (Deleted User) - March 20, 2012

Hi zaba,

Are these all appearing on the same page? If so, you can add another counter before starting the foreach:

<?php $totalCells = 0; ?>

and immediately after starting the loop:

<?php
if ( $totalCells == 13 ) {
// Clear the floats
echo "<div style='clear:both;'></div>";
//close the div then open a new one
echo "</div><div>";
// reset the counter
$totalCells = 0;
}
?>


and then before closing the foreach:

<?php $totalCells = $totalCells + 1; ?>

Don't forget to close the final container div after the end of the foreach loop.

If these results are to be on different pages you can use the getRecords setting 'perPage' to set the number of results per page to 13 (use the codegenerator view for the table you want in CMSB to see how to set up links to scroll through the pages returned etc).

Let me know if this helps,

Tom

Re: [Tom P] breaking up results into varying columns

By zaba - March 20, 2012

Hi Tom,

they are going to be on the same page, going to integrate it with a vertical scroller and a bit of jquery.

Hopefully it should all work when I finish putting it all together. I'll post back if I have any specific problems with actual code.
Really thanks a bunch for this!!

Re: [zaba] breaking up results into varying columns

By zaba - March 21, 2012

Tom,
I managed to piece it all together with my css and some jquery stuff to scroll it up and down. It works perfectly. Thanks for your code comments it helped me to understand what was going on and made it easy for me to work with. You guys are the best!!! Thanks again!