array_groupBy - additional fields.

2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 14, 2016   (RSS)

By Toledoh - January 10, 2016

Hi Guys,

I've got a page which is showing a "collection" which is a grouping of products.  Each product is also within a "series" or a sub-group.

// load record from 'collections'
list($collectionsRecords, $collectionsMetaData) = getRecords(array(
'tableName' => 'collections',
'where' => whereRecordNumberInUrl(0),
'limit' => '1',
));
$collectionsRecord = @$collectionsRecords[0]; // get first record
if (!$collectionsRecord) { dieWith404("Record not found!"); } // show error message if no record found

// load records from 'products'
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => 'collection='.$collectionsRecord['num'].''
));

$productsSortedBySeries = array_groupBy($productsRecords, 'series:label', true);

I can then display each "series", and list the "products" in each by.

<?php foreach($productsSortedBySeries as $series => $products): ?>
<div class="col-xs-4">
<h2><?php echo htmlencode($series) ?></h2>
<div class="row">
<?php foreach ($products as $record): ?>
<div class="col-xs-4">
<div class="thumbnail">
<?php echo $record['colour'] ?>
</div>
</div>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>

<?php echo htmlencode($series) ?> displays the series:label.  Is there any way I can get additional fields such as series['content'] etc?

Cheers,

Tim (toledoh.com.au)