Hey guys. I'm a first poster here. I was just wondering if you guys could possibly help me out with my code? Here's the code and a description of what it's supposed to do: <?php $RandomColourScheme=rand(0,6); if($RandomColourScheme=0){ $ColourScheme = "#CCCCFF"; } elseif($RandomColourScheme=1){ $ColourScheme = "#CCFFFF"; } elseif($RandomColourScheme=2){ $ColourScheme = "#99FF00"; } elseif($RandomColourScheme=3){ $ColourScheme = "#CCFF00"; } elseif($RandomColourScheme=4){ $ColourScheme = "#CCCCCC"; } elseif($RandomColourScheme=5){ $ColourScheme = "#FFFF99"; } elseif($RandomColourScheme=6){ $ColourScheme = "#9966FF"; } ?> PHP: Okay, the code is supposed to generate a random number between 0 and 6. The if statement is supposed to work out which number has been generated and applies a colour to the $ColourScheme varible. The HTML looks something like this: <td bgcolor="<?php print ("$ColourScheme"); ?>"> Any ideas of why it's not working? Kind regards, James.
Are you using the ".php" extension on the file? If you are not you should change it. If that doesn't work try using: <td bgcolor="<?php echo $ColourScheme;?>">
Yes, the ".php" extension is there. Thanks for the help but the echo doesn't work. I know the code works because I had this as my old code. <?php if(date("D") == "Sun") { $ColourScheme = "#CCCCCC"; } elseif(date("D") == "Mon") { $ColourScheme = "#A6CAF0"; } elseif(date("D") == "Tue") { $ColourScheme = "#E79703"; } elseif(date("D") == "Wed") { $ColourScheme = "#AE9675"; } elseif(date("D") == "Thu") { $ColourScheme = "#CFDDF4"; } elseif(date("D") == "Fri") { $ColourScheme = "#CCCCCC"; } elseif(date("D") == "Sat") { $ColourScheme = "#A6CAF0"; } ?> PHP: This one works fine. This one changes the colour depending on the day of the week.
When comparing a variabile with a number or another variable, you have to use == : if ($value == 1) { //do something } elseif ($secondvalue==2) { } PHP: