I'm trying out the modulus division with a foreach loop, and I'm having a bit trouble understanding it.
$counter = 0;
foreach($result as $row){
if(isset($row['username'])){
if (($counter) % 2 == 0){
echo "<tr class=\"r1\"><td class=\"center\"><a href=\"profile.php?username=" . $row['username'] . "\">" . $row['username'] . "</a></td></tr>";
}
else{
echo "<tr class=\"r0\"><td class=\"center\"><a href=\"profile.php?username=" . $row['username'] . "\">" . $row['username'] . "</a></td></tr>";
}
$counter++;
}
}
I want to output:
<tr class="r0">
<td><a href="profile.php?username=Bob">Bob</a></td>
<td><a href="profile.php?username=Daniel">Daniel</a></td>
</tr>
<tr class="r1">
<td><a href="profile.php?username=Dylan">Dylan</a></td>
<td><a href="profile.php?username=Bruce">Bruce</a></td>
</tr>
But currently, with my loop, I'm outputting:
<tr class="r1">
<td<a href="profile.php?username=Bob">Bob</a></td>
</tr>
<tr class="r0">
<td><a href="profile.php?username=Daniel">Daniel</a></td>
</tr>
<tr class="r1">
<td><a href="profile.php?username=Dylan">Dylan</a></td>
</tr>
<tr class="r0">
<td><a href="profile.php?username=Bruce">Bruce</a></td>
</tr>
Can someone explain to me exactly how modulus division works? Thank you.