problem: ihr wollt datensätze, zum beispiel aus einer datenbank in einer tabelle ausgeben, wobei die zeilen der tabelle abwechselnd farbigen hintergrund haben sollen.
lösungsansatz in php:
PHP-Code:
<?php
function GetDifferentColours($count) {
$Colour1 = "#C0C0C0";
$Colour2 = "#FFFFFF";
$rest = $count % 2;
if($rest) {
return $Colour1; // returns the Colour #C0C0C0
} else {
return $Colour2; // returns the Colour #FFFFFF
}
}
$myArray = array("GRAUER HINTERGRUND", "WEISSER HINTERGRUND", "GRAU", "WEISS", "GRAU");
$i = 1;
echo '<b>Output:</b><br><br><table width="50%">';
foreach($myArray as $val) {
echo '<tr><td bgcolor="'.GetDifferentColours($i).'">'.$val.'</td></tr>';
$i++;
}
echo '</table><br>';
?>