Different images for day and night...

Lee
Posts: 297
Joined: Mon 12 Jul, 2004 15.49

*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!
cdd
Posts: 2622
Joined: Fri 15 Aug, 2003 14.05

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.
SteveL
Posts: 81
Joined: Fri 22 Aug, 2003 18.47

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]">.
Lee
Posts: 297
Joined: Mon 12 Jul, 2004 15.49

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. :(
SteveL
Posts: 81
Joined: Fri 22 Aug, 2003 18.47

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.
Lee
Posts: 297
Joined: Mon 12 Jul, 2004 15.49

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...
Please Respond