Friday, March 30, 2007

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:












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:

while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)){
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>";
}

Wednesday, March 21, 2007

Oracle Date Functions

Puget Sound Oracle Users Group = Best Oracle Documentation (IMHO)

http://www.psoug.org/reference/date_func.html