appear div on maxCols
            3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 31, 2016   (RSS)          
By petrogus - May 27, 2016 - edited: May 27, 2016
Hi I would like to ask your help on this question,
 how can appear a div on start and at the end every 4 records
for example I have this code
<?php $maxCols = 4; $columnCount = 0; ?> 
<?php if (($columnCount % $maxCols) == 0) { echo "<div class=".chr(34)."row".chr(34).">";}?>
<?php foreach ($productsRecords as $record): ?>
<div class="col-md-3 >
.....
</div>
<?php endforeach ?>
 <?php if (($columnCount % $maxCols) == 0) { echo "</div>";}?>
and I would like to appear on page the following
<div class="row">
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
</div>
<div class="row">
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
<div class="col-md-3 >.....</div>
</div>
Thank you in advance
By Damon - May 30, 2016
Hi,
Try this code:
  <div class="row">
 <?php foreach ($productsRecords as $record): ?>
  <div class="col-md-3 >.....</div>
 <?php $maxCols=4; if (@++$count % $maxCols == 0): ?>
  </div>
  <div class="row">
 <?php endif; ?>
 <?php endforeach; ?>
  </div>
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/