[thelist] simple! PHP data display

Jon Haworth jhaworth at witanjardine.co.uk
Thu Aug 22 08:36:11 CDT 2002


Hi Jay,

> if ($rowcount == 1) {
>     print("<tr bgcolor=\"#FFFFCC\">\n");
> } elseif ($rowcount <> 1) {
>     print("<tr>\n");
>     $rowcount = 0;
> }
>
> There is also a two line way of alternating row colors
> with the modulus operator, but I don't remeber it right
> off-hand.

Your solution is fine, but FWIW:

$rowcount++;
if ($rowcount % 2 == 0) {
  print ("<tr bgcolor=\"#FFFFCC\">\n");
} else {
  print ("<tr>\n");
}

If you don't like big sprawling if() statements, or you're after enhanced
job security, you can squash all of the above into one line:

echo "<tr". ((++$rowcount % 2 == 0) ? " bgcolor=\"#FFFFCC\">" : ">"). "\n";

or, if you want to specify a bgcolor for both rows:

echo "<tr bgcolor=\"#". ((++$rowcount % 2 == 0) ? "FFFFCC" : "CCFFFF").
">\n";


Cheers
Jon



More information about the thelist mailing list