Identify a row alternating color

Sorry about the title I really couldn't figure out how to describe my problem in such short words

So I have this page where I display ranks.

Right now I got it down so it loops the rank name only once. Only problem I have now is making each TR block where a new rank starts a diffrent color. I wanna alternate between red and blue.

I'd want the Leader block to be blue, the vice block red and so on, third then blue and so on.


Leader: | Bob
        | Rob

Vice:   | Jim
        | John
        | Robert
        | Samuel
        | Joe

Novice: | Sarah
        | Cletus
        | Tom

$lastRankID = -1;

<?php foreach($db->query($sql) as $row): ?>
<tr bgcolor=" RED/BLUE ">
<?php if ($lastRankID <> $rankid) echo $rankname; $lastRankID = $rankid; ?>

<td><?php echo $name ?></td>

<?php endforeach ?>


$i = 0;

<?=($i = !$i) ? 'blue' : 'red'?>


will ofcourse not work, I dont wanna have diffrent row color on every TR only where a new rank starts.

Any tips for a noob?


$colors = array('red', 'blue');
$curcolor = 0;


if ($lastRankID != $rankid) {
    $curcolor = ($curcolor+1) % count($colors);
    $lastRankID = $rankid;
echo "<TR class='{$colors[$curcolor]}'>";

Need Your Help

Unfortunately, (App Name) has stopped

android android-layout android-intent

I am able to compile, build, and install the project successfully. When I click in a button, the app says: Unfortunately has stopped. Could you please help me figure this out?

Push Notifications Cannot get Device Token

ios push-notification

I'am trying to get the device token so I can send a notification to it but i keep getting the error "enabledRemoteNotificationTypes is not supported in iOS 8.0 and later."