Trouble integrating content inside table

2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 24, 2010   (RSS)

By Hansaardappel - February 23, 2010 - edited: February 23, 2010

Sorry about spamming the board, but I have a question again :)

I want to put the content of a section inside two columns, but don't seem to get it right. I tried two different ways:

<table border="1" width="100%"><?php foreach ($fpvideoRecords as $record): ?>
<?php echo "<tr><td width=50%>", $record['content'], "</td>", "<td width=50%>", $record['content = 6'], "</td></tr>" ?>
<?php endforeach; ?></table>

The result: Notice: Undefined index: content = 6

<table border="1" width="100%"><?php foreach ($fpvideoRecords as $record): ?>
<?php echo "<tr><td width=50%>", $record['content'], "</td></tr>" ?>
<?php endforeach; ?></table>


This one does work, but as expected, it shows only one column per row.

Any idea on how to integrate the content in 2 columns per row?

Thanks again [unsure]

Re: [Hansaardappel] Trouble integrating content inside table

No Problem Hansaardappel,

The more we do, the more questions come up.

Here's an excerpt from my CMSB Cookbook www.thecmsbcookbook.com that addresses your question.

To make your table automatically wrap every 2 columns you can use:

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

Which is just a way of saying "Every 2 columns insert "</tr><tr>"".

Here’s a single row example using the thumbnail2 image as a link to a detail page, separate Title and Subtitle fields, a hidden border for IE and a fixed height for the image cell so that everything lines up nicely.

<table width="100%" border="0" cellpadding="5">
<tr>
<?php foreach ($your_sectionRecords as $record): ?><?php foreach ($record['image'] as $upload): ?>
<td align=”center” height="350" valign="bottom">
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" style="border:hidden" /><br /><div align="center" class="medium-title"><?php echo $record['title'] ?></div>
<div align="center" class="medium-text"><?php echo $record['sub_title'] ?></div></a>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?><?php endforeach ?>
</tr>
</table>


Similarly, if you’re not using images this code will output a </tr><tr> after every 2 <td>...your content...</td> lines:

<table border="1">
<tr>

<?PHP foreach ($yourrecords as $record): ?>
<td>
<?PHP echo $record['your_content'] ?><br/>
</td>
<?PHP $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?PHP endif; ?>
<?PHP endforeach; ?>
</tr>
</table>


Use your own variable names instead of $yourrecord.

Hope that gets you going.

Best,

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