Sub Grouping in List Views - One Way of Doing It.

14 posts by 6 authors in: Forums > CMS Builder
Last Post: March 12, 2010   (RSS)

By Chris - October 20, 2009

Hi rez,

You can use the getListLabels() function to lookup the label for a num in a List field. You'll need to supply that function with the name of the table and field it's doing the lookup from:

$tableName = 'food';
$fieldName = 'group';
$fieldValue = $record['group'];
$label = getListLabels($tableName, $fieldName, $fieldValue);
echo $label;


Change the code in red above to reflect your configuration. Please let me know if you have any questions or run into any problems.
All the best,
Chris

Re: [chris] Sub Grouping in List Views - One Way of Doing It.

By rez - March 9, 2010

I tried getListLabels without luck. I dont get where it goes.

I put a comment where I'm getting numbers. Is that where the function goes? No luck. In the items table the list is named category and has fields of 'num' for values and 'title' for names. I set the getListLabels up for the items table, right? I kept getting my last category name displayed for every category.

Could you clear up where the getListLabels() function goes to loop out my categories below? So confusing, and this isonly a small part:

list($beverage_itemsRecords, $beverage_itemsMetaData) = getRecords(array(
'tableName' => 'beverage_items',
));

list($beverage_categoriesRecords, $beverage_categoriesMetaData) = getRecords(array(
'tableName' => 'beverage_categories',
));

?>



<?php

// list a category name , then all its entries using a variable named group
$old_group = ''; // init blank var.
foreach ($beverage_itemsRecords as $record):
$group = $record['category']; // load sub-group value from record.
if ($group != $old_group) { // If different from the last sub-group value, print the sub-group name.
foreach ($beverage_categoriesRecords as $record2):
if ($group == $record2['title']){
echo "<a name=\"{$record2['num']}\" id=\"{$record2['num']}\"></a>";
}
endforeach;
echo "<div class=\"cat-wrapper\">
<div class=\"cat-header\">
<span class=\"l-ribbon\"></span>"?>

<h2 class="menu-category"><?php echo $group ?></h2></div></div> <!-- this is where the number is echoed, i want category titles. -->
<?php foreach ($beverage_categoriesRecords as $record2):
if ($group == $record2['title']){
if ($record2['description']){
echo "<div class=\"cat-desc\">";
echo $record2['description'];
echo "</div><br />";
}
}
endforeach;
}?>

By Chris - March 9, 2010

Hi rez,

How about replacing this line:

<h2 class="menu-category"><?php echo $group ?></h2></div></div> <!-- this is where the number is echoed, i want category titles. -->

with this:

<h2 class="menu-category"><?php
$labels = getListLabels('beverage_items', 'category', $record['category']);
echo join('<br/>', $labels);
?></h2></div></div> <!-- this is where the number is echoed, i want category titles. -->


Does that help?
All the best,
Chris

Re: [chris] Sub Grouping in List Views - One Way of Doing It.

By rez - March 12, 2010

It's working great, yes. Thanks.