array_groupBy - additional fields.

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

Hi Tim, 

I thought I'd add the solution we found to this problem in here. 

The problem was that we want to get the appropriate series data before we loop through the products. So the easiest solution is to get each series records directly from the database as we need them:

  <div class="row">
    <?php foreach($productsSortedBySeries as $seriesNum => $products): ?>
      <div class="col-xs-4">
        <?php $series = mysql_get('series', $seriesNum); ?>
        <h2><?php echo @$series['title']; ?></h2>
        <p><?php echo @$series['content']; ?></p>
        <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 ?>
  </div>

So the above code uses the current series number to retrieve the related series record, and display its title and content before we cycle through the product records.

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com