Laying Out Photos x 3 columns

3 posts by 3 authors in: Forums > CMS Builder
Last Post: April 21, 2009   (RSS)

By benedict - April 20, 2009

Hi guys,

I'm using the standard code to layout profile photos in a 3 column layout so they wrap down to the next line:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php foreach ($our_peopleprincipalRecords as $record): ?>
<?php foreach ($record['headshot'] as $upload): ?>
<td class="people"><a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /></a></td>
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif ?>
<?php endforeach ?>
<?php endforeach; ?>
</tr>
</table>


And using this at the top:

<?php
require_once "/home/jglimpse/public_html/mst/cmsAdmin/lib/viewer_functions.php";

list($our_peopleprincipalRecords, $our_peopleprincipalMetaData) = getRecords(array(
'tableName' => 'our_people',
'allowSearch' => '0',
'where' => ' position LIKE "%Principal%" ',
));
?>


But a freaky thing is happening. I originally was going to repeat this three times for the Principals, The Associates & Special Counsels for this law firm. Troubles arose, so to double check, I just pasted the same code three times in the body of the page.

The layout is different for each of the three tables, even though the code is identical - i.e.

- The first table presents a row of 3, another row of 3, and then the remaining 2 (correct)
- The next table has 1 image in the first row, 3 rows of 3 photos and then 1 photo in the last row (incorrect)
- The final table has 2 photos in the first row and then 3 x 3 rows (incorrect).

For the first time ever in using CMS Builder, I have no idea where to start in fixing this - would really appreciate any help you could offer. You can see the end result at www.glimpse.net.au/mst/ourpeople.php

Thanks.

Re: [benedict] Laying Out Photos x 3 columns

By gkornbluth - April 21, 2009

You may be running into this issue...

If you’re going to use that little code snippet multiple times on the same page, you'll need to use a different variable instead of $count or it will remember the count from the last section and increment that.

Instead of this:

<?php $maxCols=3; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

Use this:

<?php $maxCols=3; if (@++$count1 % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php $maxCols=3; if (@++$count2 % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php $maxCols=3; if (@++$count3 % $maxCols == 0): ?></tr><tr><?php endif; ?>

As Dave says...

Hope that helps,

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