Add class to third element - IF Else %
I'm running sum basic content from a XML file and have the below which outputs things ok.
My problem is when I try and use an if else statement to supply a div class="last" to every third element, it adds it to all the div elements.
Wondering what I'm doing wrong?
Can anybody spot the problem with syntax below?
<?php foreach ($hotels->hotel as $hotel): ?>
<?php if($i % 3 == 0) : ?>
<?php else: ?>
<?php endif; ?>
<img src="images/<? echo $hotel->img->name ?>">
<h3><? echo $hotel->name ?></h3>
<p><? echo $hotel->description ?></p>
<p><? echo $hotel->address->postcode ?></p>
<? endforeach ?>