Jump to content

image to time


boemboem

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.