Forcing columns in multi row tables

7 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2009   (RSS)

By gkornbluth - January 26, 2009

Hi again,

Hope someone can help.

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: [gkornbluth] Forcing columns in multi row tables

By Dave - January 27, 2009

Hi Jerry,

Can you create a quick mockup url so I can see what it's suppose to look like? Once I can see that I should have a better idea.

Thanks! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [gkornbluth] Forcing columns in multi row tables

By Dave - January 27, 2009

Hi Jerry,

Thanks for that. Those can be tricky. We could write some PHP code to do it, but it might be a bit complicated. Another way to do it is to use a table inside a table (or CSS, divs etc) so you can display the image and text in one tablecell (using a table inside that cell to align in).

How many records do you want to show on the page? With complex layouts another way is to refer to each record by number and lay them all out manually rather than looping over them. You can do that like this: $records[0]['title'], $records[1]['title'], etc. And test if a record is defined like this:

<?php if (@$records[0]): ?>
... show record 0 (which is actually record 1, but programmers sometimes count from zero)...
<?php endif ?>

Let me know if either of those would work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Forcing columns in multi row tables

By gkornbluth - January 27, 2009

Thanks for taking the time to respond Dave,

The table within a table approach sounds feasible. since I'd like not to limit the number of images.

Not sure how you would approach it though. How would it alter the PHP code above?

Thanks

Jerry
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: [gkornbluth] Forcing columns in multi row tables

By Dave - January 28, 2009

Hi Jerry,

Maybe something like this:

<td align="center" valign="middle" width="50%">

<table border="1" cellspacing="0" cellpadding="0">
<tr><td>
<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></tr>
</tr></table>

</td>


And you'd probably want a fixed height on the td with the thumbnail so they all line up the same.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Forcing columns in multi row tables

By gkornbluth - January 28, 2009

It worked perfectly.

Thanks

Jerry
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