It works after you change a few items. The errors are in red on the first code, and the second you will see the corrections.
original:
PHP Code:
<?php
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
if ($h < 7[COLOR="Red"])[/COLOR] && [COLOR="Red"]([/COLOR]$d == 0) $img = 'fish.jpg';
else if ($h < 20[COLOR="Red"])[/COLOR] && [COLOR="Red"]([/COLOR]$d == 0) $img = 'frogs.jpg';
else $img = 'potatoes.jpg';
//if it's before 7am on Sunday, use fish image
//if not and it's before 8pm on Sunday, use frogs
//otherwise, potatoes
?>
The html for the page goes here...
<html>
...
<body>
...
<img src="<?php echo $img; ?>">
...
</html>
corrected:
PHP Code:
<?php
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
if ($h < 7 && $d == 0) $img = 'fish.jpg';
else if ($h < 20 && $d == 0) $img = 'frogs.jpg';
else $img = 'potatoes.jpg';
//if it's before 7am on Sunday, use fish image
//if not and it's before 8pm on Sunday, use frogs
//otherwise, potatoes
?>
The html for the page goes here...
<html>
...
<body>
...
<img src="<?php echo $img; ?>">
...
</html>
The corrections I have done were to take out the extra parenthesis "( )" (not sure on spelling). In the if - else statements you only need an opening and closing set, nothing between the && (and) or || (or). Other than that, it works. I have tested it on my home server and was able to change the times and whatnot and it works as expected.
Let me know if you need any more help.
Bookmarks