boemboem Posted February 16, 2009 Share Posted February 16, 2009 Hello all, The code beneath should change the image on my homepage, but it doesn't, because the image didn't change at 8.00 this morning. (header1.jpg) and displayed header2.jpg I know the code isn't completly clean, this is because the code was origin a if the else statement for $h < 7, $h <12 Any help would be great. <?php $h = date('G'); //set variable $h to the hour of the day //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. if ($h = 1) $img = './style/header2.jpg'; if ($h = 2) $img = './style/header2.jpg'; if ($h = 3) $img = './style/header2.jpg'; if ($h = 4) $img = './style/header2.jpg'; if ($h = 5) $img = './style/header2.jpg'; if ($h = 6) $img = './style/header2.jpg'; if ($h = 7) $img = './style/header2.jpg'; if ($h = $img = './style/header1.jpg'; if ($h = 9) $img = './style/header1.jpg'; if ($h = 10) $img = './style/header1.jpg'; if ($h = 11) $img = './style/header1.jpg'; if ($h = 12) $img = './style/header1.jpg'; if ($h = 13) $img = './style/header1.jpg'; if ($h = 14) $img = './style/header1.jpg'; if ($h = 15) $img = './style/header1.jpg'; if ($h = 16) $img = './style/header1.jpg'; if ($h = 17) $img = './style/header1.jpg'; if ($h = 18) $img = './style/header1.jpg'; if ($h = 19) $img = './style/header2.jpg'; if ($h = 20) $img = './style/header2.jpg'; if ($h = 21) $img = './style/header2.jpg'; if ($h = 22) $img = './style/header2.jpg'; if ($h = 23) $img = './style/header2.jpg'; else $img = './style/header1.jpg'; ?> Quote Link to comment Share on other sites More sharing options...
AV1611 Posted February 16, 2009 Share Posted February 16, 2009 ... and the image that shows is always: ./style/header2.jpg if ($h = 10) $img = './style/header1.jpg'; will always be TRUE because $h = 10 is setting a variable. You want: if ($h == 10) $img = './style/header1.jpg'; which is a comparison. Quote Link to comment Share on other sites More sharing options...
boemboem Posted February 16, 2009 Author Share Posted February 16, 2009 oh lol, I see now The image changed indeed, and apparently it looks at the server time, because it does not change when I changed my system time and did change after 9.00 am Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Ugh... how about $h = date('G'); //set variable $h to the hour of the day //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. if ($h > 7 && $h < 19) { $img = './style/header1.jpg'; } else { $img = './style/header2.jpg'; } Quote Link to comment Share on other sites More sharing options...
boemboem Posted February 16, 2009 Author Share Posted February 16, 2009 It looks like a better solluion because I dont need a different image every hour, but it does not work and it says that it cant find a image. http://www.coldcharlie.nl/ Quote Link to comment Share on other sites More sharing options...
boemboem Posted February 16, 2009 Author Share Posted February 16, 2009 my bad, I forget to put the <?php ?> in it Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 That helps usually Quote Link to comment Share on other sites More sharing options...
AV1611 Posted February 16, 2009 Share Posted February 16, 2009 Ugh... how about $h = date('G'); //set variable $h to the hour of the day //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. if ($h > 7 && $h < 19) { $img = './style/header1.jpg'; } else { $img = './style/header2.jpg'; } LOL... I was gonna say that but I didn't wanna lose focus on the actual question =P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.