Laying out tables to force data

4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 23, 2009   (RSS)

Re: [misery217] Laying out tables to force data

By Dave - January 22, 2009

Hi Aaron, Welcome to the CMS Builder forum! :)

If I'm understand correctly there's a couple ways to do that. The CSS way is to have each image in a div that has something like: style="float: left; width: 200px". This will make them flow from left to right and wrap when they run out of space (you can put them inside a bigger fixed width container).

Or with a table you can have one tablecell per image and insert a closing and opening TR every X images. Here's a code snippet that does that:

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

Which is just a way of saying "Every 3 images insert "</tr><tr>"". So you'd have something like this:

<table>
<tr>
<?php foreach ($record['uploads'] as $upload): ?>
<td> ... show upload ... </td>

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

<?php endforeach ?>
</tr>
</table>


Hope that makes sense. Let me know if you have any other questions.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Laying out tables to force data

While we’re on the subject, I’ve got another question about columns.

All of the posts that I could find deal with rows of single cells repeating after a number of columns.

I'm trying to get a set of 2 rows to repeat after 2 columns and for some reason I can’t seem to find the magic. (I know that I’m going to feel really dumb when I see what’s wrong)

Thanks,

Jerry Kornbluth

Here’s the single cell solution that works: http://www.marshazart.com/glassart3.php

<table width="100%" border="0" cellpadding="10">
<tr>
<?php foreach ($glass_artRecords as $record): ?><?php foreach ($record['image'] as $upload): ?>
<td align="center" valign="middle" width="50%"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" />
<div class="medium-title"><?php echo $record['title'] ?></div>
<div class="medium-text"><?php echo $record['sub_title'] ?></div>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?><?php endforeach ?>
</tr>
</table>

Here’s what I’ve tried for the 2 row solution that doesn’t work (the sets of rows don’t appear under each other): http://www.marshazart.com/glassart4.php

<table width="100%" border="0" cellpadding="10">
<tr>
<?php foreach ($glass_artRecords as $record): ?><?php foreach ($record['image'] as $upload): ?> <td align="center" valign="middle" width="50%"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" />
</td><tr></tr><td>
<div class="medium-title"><?php echo $record['title'] ?></div>
<div class="medium-text"><?php echo $record['sub_title'] ?></div>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?><?php endforeach ?>
</tr>
</table>
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

Re: [Dave] Laying out tables to force data

Wow, okay, the table code was EXACTLY what I was needing!!! Thanks so much Dave!! No on to more questions!