I am trying to loop through an array, and every 3 loops create a new row, however I am having difficulty getting it to work, currently my code looks like this,
<li class="row">
<?php for ($i = 0; $i < count($results); $i++) : ?>
<div class="grid_8">
<div class="candidate <?php if ($i % 3 == 2) echo "end"; ?>">
<div class="model_image shadow_50"></div>
<dl>
<dt><?php echo $results[$i]['first_name']; ?> <?php echo $results[$i]['surname']; ?></dt>
<dd>
<?php echo $results[$i]['talent']; ?>
<ul>
<li><?php echo anchor("/candidates/card/" . strtolower($results[$i]['first_name']) . "-" . strtolower($results[$i]['surname']), "View Details", array('class' => 'details')); ?></li>
<li><?php echo anchor("/candidates/card/" . strtolower($results[$i]['first_name']) . "-" . strtolower($results[$i]['surname']), "View Showreel", array('class' => 'showreel')); ?></li>
<li><?php echo anchor("/candidates/card/" . strtolower($results[$i]['first_name']) . "-" . strtolower($results[$i]['surname']), "Shortlist", array('class' => 'shortlist')); ?></li>
</ul>
</dd>
</dl>
</div>
</div>
<?php if ($i % 3 == 3) : ?>
</li><li class="row">
<?php endif; ?>
<?php endfor; ?>
However this just creates one row, and with all my results in it, whereas it should be 1 li with a class of row, and then 3 .grid_8 divs and then another row.
Where am i going wrong?
The issue is your modulus equation. The remainder will never reach 3, and will be a pattern of (0,1,2,0,1,2,0,1,2). So you change it to equal 2.