Page is a not externally linkable
generic - 1:41 am on Jan 17, 2013 (gmt 0)
I'm trying to output data from mysql using a while loop into a framework. I need to have classes assigned to certain Nth iterations to maintain the layout provided by the framework.
The first iteration and every fourth one after have one class (alpha, ie, first div in row).
The fourth div and every fourth after that have another (omega, ie, last div in row). So I need something roughly like this:
<div class="alpha"> <div> <div> <div class="omega">
<div class="alpha"> <div> <div> <div class="omega">
<div class="alpha"> <div> <div> <div class="omega">
.. and so on
I've been trying to figure it out using the modulus operator but can't seem to wrap my head around how to target multiple Nth iterations. Can someone lend a guy a hand? Is there a better way?
Here's my gnarley existing code
$x = 0;
while ($row = mysql_fetch_assoc($result)){
if ($x % 1 == 0 || 5 == 0) {
echo '<div class="alpha">';
} elseif ($x == 4) {
echo '<div class="omega">';
} else {
echo '<div>';
}
}
Thanks in advance.
gen