View Single Post
Old 03-20-2009, 05:37 PM   #2 (permalink)
CrazeD
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,688

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: PHP to alternate row columns

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';
?>

__________________

Need website help? PM me!
CrazeD is offline