Well here's what you'd do if you wanted every row to be an alternating color, then it's pretty easy to go to what you want to use.
First create a variable $switcher and set it to 1. Then let's say you have a loop that will print out each row, or if you're pulling them out of a DB, something like this:
while ($row = mysql_fetch_row($getrow)) {
if ($switcher == 1)
$bgcolor = "#FFFFFF";
else
$bgcolor = "#CCCCCC";
printf('<tr bgcolor="%s"><td>%s</td></tr>', $bgcolor, $row[0]);
$switcher *= -1;
}
What the last line does is multiply $switcher by -1 and restore it. Remembering back from Algebra class, multiplying a number by -1 repeatedly will alternate its sign (pos or neg). So each time through the loop, $bgcolor will get a different value.
Now to do what you want would be slightly more complicated, but still not too difficult. You'd could use something like this:
$lastrow = 'x' // This just so that it'll never match the value from the DB the first time through the loop
$lastcolor = '#FFFFFF' // Makes sure that white is always used first
while ($row = mysql_fetch_row($getrow)) {
if ($lastrow == $row[0]) {
$bgcolor = $lastcolor;
}
else {
if ($switcher == 1) {
$bgcolor = "#FFFFFF";
$lastcolor = "#FFFFFF";
}
else
$bgcolor = "#CCCCCC";
$lastcolor = "#CCCCCC";
}
}
// Print the row, same as first example
$switcher *= -1; // Keep the variable alternating under either case
$lastrow = $row[0]; // Current row will be last row for the next time through the loop
}
That should do it!
EDIT - Testing out the new php vB tag.