View Single Post
Old 03-20-2009, 03:08 PM   #1 (permalink)
bukwus
 
Newb Techie

Join Date: Sep 2006

Posts: 27

bukwus is on a distinguished road

Default PHP to alternate row columns

Hi

I'm a beginner to functions and I tried using the following to alternate the background color of rows with no luck. Can anyone hlep?

<?php
function backgroundColor() {
if ($bg == 'yes') {
echo '';
$bg = 'no';
}
elseIf ($bg == 'no') {
echo 'bgColor';
$bg = 'yes';
}
else {
echo 'error';
}
}

$bg = 'no';
?>

<style>
.bgColor {
color:gray;
}
</style>

<div class="<?php backgroundColor() ?>">
Row 1 content
</div>

<div class="<?php backgroundColor() ?>">
Row 2 content
</div>

<div class="<?php backgroundColor() ?>">
Row 3 content
</div>
bukwus is offline