Categories & Columns

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

By Kenny - September 21, 2009

I am trying to combine a couple of chunks of code without much luck.

I have a list of items divided up into categories.

So using the following code I can get the name of the category to to only show up once and then list the items in that category.

<?php
$lastCategory = "";
foreach ($linksRecords as $record):
$showHeader = false;
if ($record['category'] != $lastCategory) {
$lastCategory = $record['category'];
$showHeader = true;
}
?>
<?php if ($showHeader): ?>

<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td><b><font face="Arial" color="#800000"><?php echo $record['category'] ?></font></b></td>
</tr>
</table>
<?php endif ?>

<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td><font face="Arial" size="2">
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></font><br></td>
</tr>
</table>
<?php endforeach; ?>



But instead of going straight down the page, I want to put them into columns of three. Normally I would use this:

<table>
<?php foreach ($linksRecords as $record): ?>
<td>
//DISPLAY ALL CODE HERE
</td>
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif ?>
<?php endforeach ?>
</table>



Now when I tried to fuse the two together I get horrible results (like Dr Frankenstein).


Any ideas?


Kenny