Categories & Columns

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

Re: [sagentic] Categories & Columns

By Chris - September 21, 2009

Hi Kenny,

At some point, it becomes simpler to restructure your data.

Try this:

<?php
// construct a list of categories
$categories = array();
foreach ($linksRecords as $record) {
if (@$record['category']) {
if (!@$categories[$record['category']]) {
$categories[$record['category']] = array(
'label' => $record['category'],
'records' => array()
);
}
$categories[$record['category']]['records'][] = $record;
}
}
?>

<?php foreach ($categories as $category): ?>

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

<!-- records in this category -->
<table>
<tr>

<?php $count = 0; ?>

<?php foreach ($category['records'] as $record): ?>

<?php $maxCols=3; @$count++; if (($count-1) % $maxCols == 0 && $count != 1): ?>
<!-- next row -->
</tr><tr>
<?php endif ?>

<!-- record start -->
<td><font face="Arial" size="2">
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></font><br>
</td>

<?php endforeach; ?>

</tr>
</table>

<?php endforeach; ?>


Hope this helps! Please let me know if you have any questions. :)
All the best,
Chris