Alternating row color by groups
As a DBA, I spend a lot of time looking at lists of rows and grouping them in various ways. Visually it helps to alternate the color like so:
if(!$temp || $temp_zname <> $row[MEMBER_TO_GROUP_BY]){
$temp = $row[MEMBER_TO_GROUP_BY];
$bgcolor = ($bgcolor == 'lightblue') ? '' : 'lightblue';
}
print "<tr bgcolor=$bgcolor>";
print "<td>". $row[MEMBER_TO_GROUP_BY] . "</td>";
print "</tr>";
}
| group 1 |
| group 1 |
| group 1 |
| group 2 |
| group 2 |
| group 3 |
| group 3 |
| group 3 |
| group 4 |
I can never remember the logic to do this so hear it is (in PHP/Oracle) for future reference:
if(!$temp || $temp_zname <> $row[MEMBER_TO_GROUP_BY]){
$temp = $row[MEMBER_TO_GROUP_BY];
$bgcolor = ($bgcolor == 'lightblue') ? '' : 'lightblue';
}
print "<tr bgcolor=$bgcolor>";
print "<td>". $row[MEMBER_TO_GROUP_BY] . "</td>";
print "</tr>";
}

0 Comments:
Post a Comment
<< Home