array_groupBy and display image

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

By Toledoh - September 17, 2020

Hi All.

I'm grouping records by brand with the code below:

// load records from 'independent_research_reports'
list($researchRecords, $researchMetaData) = getRecords(array(
'tableName' => 'independent_research_reports',
'where' => "`typeNum` = '1'",
'loadUploads' => true,
'allowSearch' => false,
));
$researchSeries = array_groupBy($researchRecords, 'brandsNum:label', true);

Sor to display the brand, I use;

<?php foreach($researchSeries as $series => $items): ?>
<div class="row">
<div class="col"><h3><?php echo htmlencode($series) ?></h3></div>
</div>
   <?php foreach ($items as $record): ?>.....<?php endforeach ?>
<?php endforeach ?>

My question is, how do I go about displaying an image with each brand?

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

[IMAGE HERE]
<h3><?php echo htmlencode($series) ?></h3></div>

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

Cheers,

Tim (toledoh.com.au)

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);

Thoughts?

Cheers,

Tim (toledoh.com.au)

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.

https://www.interactivetools.com/support/request/

Carl

PHP Programmer

interactivetools.com