Re: [sparks] Categories and records grouped on same page
Hi Sparks
I have some code for you to try out. It's actually a little more advanced than what we normally post but it is copy and pasteable so you should be ok. Here's the code:
<?php
$html = "";
// loop over categories
$categoryOptions = getListOptions('meet_our_advertisers', 'category'); // tablename, fieldname
foreach (array_keys($categoryOptions) as $categoryName) {
$heading = "<br><br><strong>$categoryName</strong><br>";
// loop over records
$rows = "";
foreach ($meet_our_advertisersRecords as $record) {
$isRecordInCategory = strpos($record['category'], "\t$categoryName\t") !== false;
if ($isRecordInCategory){ $rows .= $record['title'] . "<br/>";}
}
// add to html
if ($rows) {
$html .= $heading . $rows;
}
}
//
print $html;
?>
Just paste that where you want the list of categories and articles to appear. It's setup to only display a category name if there is actually an article in it.
Let me know how you make out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/