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'; ?> Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/ 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. Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763201 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 Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763206 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'; } Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763207 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/ Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763219 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 Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763226 Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 That helps usually Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763227 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 Link to comment https://forums.phpfreaks.com/topic/145380-image-to-time/#findComment-763438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.