View Single Post
Old 03-24-2009, 12:44 PM   #3 (permalink)
bukwus
 
Newb Techie

Join Date: Sep 2006

Posts: 27

bukwus is on a distinguished road

Default Re: PHP to alternate row columns

Thank you. This works great.

Quote:
Originally Posted by CrazeD View Post
Your function works, however you have a scope problem. By default, functions don't inherit variables from the rest of the script. It has no idea that $bg was ever initialized.

To fix this, just add global $bg; to the top of your function.

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

$bg 'no';
?>

bukwus is offline