[英]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. 我现在唯一的问题是使每个TR块在新等级开始时都使用不同的颜色。 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块为蓝色,副块为红色,依此类推,第三个块再为蓝色,依此类推。
_____________
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 ">
<td>
<?php if ($lastRankID <> $rankid) echo $rankname; $lastRankID = $rankid; ?>
</td>
<td><?php echo $name ?></td>
</tr>
<?php endforeach ?>
This: 这个:
$i = 0;
<?=($i = !$i) ? 'blue' : 'red'?>
$i++;
will ofcourse not work, I dont wanna have diffrent row color on every TR only where a new rank starts. 当然,这是行不通的,我不想只在新等级开始的时候在每个TR上使用不同的行颜色。
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]}'>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.