Page 1 of 1

Different images for day and night...

Posted: Mon 28 Feb, 2005 06.12
by Lee
*Screams like a girl*

Does anyone know if there is a way to change a table background image according to the time of day?

And if not that, then a way to change the body background image according to the time of day? (Without having to use someone else's script!)

:( Thanks!

Posted: Mon 28 Feb, 2005 18.00
by cdd
Yep... I'm too tired to write a script right now for you but it involves javascript and dynamic styling. I imagine it could be done with server-side scripts too.

Posted: Mon 28 Feb, 2005 21.48
by SteveL
Indeed, if you were able to include PHP, just put a little something like this:

Code: Select all

<?php if (date("G") < "6" || date("G") > "21"){ echo "image1.jpg"; } else { echo "image2.jpg"; } ?> 
Into the background tag in the table. For example; <td background="<?php if (date("G") < "6" || date("G") > "21"){ echo "image1.jpg"; } else { echo "image2.jpg"; } ?>">. Currently, if it's before 6am and after 10pm, it'll show image1.jpg; if it's any other time it'll give a nice image2.jpg.

Obviously you can change the time of day and the images it puts by changing the relevant values.

[edit] To change the body background, just stick exactly the same code into <body background="

Code: Select all

[/b]">.

Posted: Mon 28 Feb, 2005 22.42
by Lee
SteveL wrote:Indeed, if you were able to include PHP, just put a little something like this:

Code: Select all

<?php if (date("G") < "6" || date("G") > "21"){ echo "image1.jpg"; } else { echo "image2.jpg"; } ?> 
Into the background tag in the table. For example; <td background="<?php if (date("G") < "6" || date("G") > "21"){ echo "image1.jpg"; } else { echo "image2.jpg"; } ?>">. Currently, if it's before 6am and after 10pm, it'll show image1.jpg; if it's any other time it'll give a nice image2.jpg.

Obviously you can change the time of day and the images it puts by changing the relevant values.

[edit] To change the body background, just stick exactly the same code into <body background="

Code: Select all

[/b]">.[/quote]

Thanks for your help! But I've just tried it and it doesn't work. I put the code in exactly as you said and this...

< "6" || date("G") > "21"){ echo "night.jpg"; } else { echo "day.jpg"; } ?>">

...shows up in the table with no background. :(

Posted: Mon 28 Feb, 2005 23.07
by SteveL
It's not executing the code on the server side then. Is PHP installed? Have you set the .html file extension (or whatever it is) to be parsed by PHP in your server config/.htaccess files? If not, try giving the file a .php file extension.

Posted: Tue 01 Mar, 2005 00.17
by Lee
Oops, sorry my mistake. It's working now, I tried changing the times to see if the daytime image would show, but it doesn't. I changed 21 to 5 and left the 6 as it is - so the night time image shows before 6am and after 5am, which should make it show the daytime image now - that's right isn't it?!

Or maybe I'll just set it back to how it was and wait until tomorrow morning...