array_groupBy and display image

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 23, 2020   (RSS)

By Carl - September 18, 2020 - edited: September 23, 2020

Hi Toledoh,
Were you only wanting to display a single image? In your getRecords function, you are including the uploads in your results so the following code should do the trick you're wanting. Note: I haven't tested it, so you might need to change some things to get it to work. If you want to display multiple images, you can just loop the $image variable and get every image attached to the record.

<?php foreach($researchSeries as $series => $items): ?>
	<div class="row">
	<div class="col">

	$image = $items['images'];
if (!empty($images[0]['urlPath'])):
	<img src="<?php echo $images[0]['urlPath']; ?>">

    <h3><?php echo htmlencode($series) ?></h3></div>

       <?php foreach ($items as $record): ?>.....<?php endforeach ?>
    <?php endforeach ?>

PHP Programmer

By Toledoh - September 18, 2020

Thanks Carl - however that's not working.

I kind of think that this is because the code you've supplied is to display the image per research record - whereas I'm trying to get the image associated to each "brand" based on the grouping

$researchSeries = array_groupBy($researchRecords, 'brandsNum:label', true);


Tim (

By Carl - September 23, 2020

What if you created a $researchRecords loop first and then loop over other items? It might be easier if you submitted a support request so I can see how everything is being joined together and I can more specifically help with a code snippet.


PHP Programmer