Change color of next row from MySQL Database PHP

<?php
$arr = array(1,1,1,4,4,7,3);
$old_value = 0;
$colour = 'blue';
echo '<table>';
foreach ($arr as $key => $value)
{
 if ($old_value == $value)
 {
 //colour stays the same
 }
 else
 {
 if($colour == 'blue')
 {
 $colour = 'yellow';
 }
 else
 {
 $colour = 'blue';
 }
 $old_value = $value;
 }
 echo '<tr style="background-color:' .$colour . '"><td>' . $value . '</td></tr>'; 
}
echo '</table>';
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s