I have a loop that displays <li>‘s and I need to add a class to the 1st and then every six <li>‘s
Example:
while ($db_field = mysql_fetch_assoc($result)) {
<li (if mod of 6 add class="something")>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li class="something">Six</li>
<li>Seven</li>
}
...
It’s quite easy using the modulus
%operator:The
($counter++) % 6expression means the remainder of $counter divided by 6, then increment $counter. If the remainder is zero (and this is true for 0, 6, 12, …), then you print the<li>with a class name, else you did not.