Hey, I'm using a while loop to display all the rows of a table in my database, and wondered if anyone knows how I can make it so the background color of each row alternates between two different colors. I'm using php to call the information, so I can stick some HTML in there if needed, but is this possible?

It can be done, just store the colour you want in a variable and swap it with a 2nd colour every time you go around the loop

Something like this:

$bg = '#FF0000';
while ($row = mysql_fetch_array($result)) {
  if ($bg == '#FF0000') $bg = 'FFFF00';
  else $bg = '#FF0000';
 $output .= "<tr bgcolor=\"#" . $bg . "\">" . "<td>" . $row['data'] . "</td></tr>"
}
echo $output;

Thanks, that worked great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.