deed02392 Posted November 10, 2007 Share Posted November 10, 2007 Hi, I'm looking to have a php script which echoes the html tags for an image depending upon the time. I played around with an if statement which is as follows: <?php if (time < 11) { ?> <img src="image/main/sunrise.jpg" alt="Good morning." width="599" height="488" hspace="30" align="middle" border="4"/> <?php } else if (time < 18) { ?> <img src="image/main/day.jpg" alt="Good afternoon." width="599" height="488" hspace="30" align="middle" border="4"/> <?php } else if (time < 10) { ?> <img src="image/main/evening.jpg" alt="Good evening." width="599" height="488" hspace="30" align="middle" border="4"/> <?php } ?> But it just seems to display sunrise despite the fact it is evening now. Also, I'm not sure if this function really works like this? I think this can be done with javascript, but i'd really like to do it in PHP as that means no worries about browser incompatibilities. Thanks in advanced! Quote Link to comment Share on other sites More sharing options...
grlayouts Posted November 10, 2007 Share Posted November 10, 2007 ok sorry a wee edit. 1. you haven't set the date() function 2. your images are not being echo'd. Quote Link to comment Share on other sites More sharing options...
deed02392 Posted November 10, 2007 Author Share Posted November 10, 2007 Used date("H") instead! Hope this helps. Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 10, 2007 Share Posted November 10, 2007 make it easier <font size="4"> <script language=javascript> <!-- function greeting() { Now = new Date() Hour = Now.getHours(); if (Hour < 5) msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 align=middle border=4/>" else if(Hour <12) msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30align=middle border=4/>" else if(Hour < 18) msg ="<img src=image/main/day.jpg alt=Good afternoon. width=599 height=488 hspace=30 align=middle border=4/>" else if (Hour < 24) msg ="<img src=image/main/evening.jpg alt=Good evening. width=599 height=488 hspace=30 align=middle border=4/>" return( msg ) } document.write(greeting()) //--> </script> </font> works and tested enjoy mike Quote Link to comment Share on other sites More sharing options...
deed02392 Posted November 10, 2007 Author Share Posted November 10, 2007 lol thanks mike, but this didn't work at all on internet explorer 6. :'( Quote Link to comment Share on other sites More sharing options...
deed02392 Posted November 10, 2007 Author Share Posted November 10, 2007 oh wait it doesn't work on anything else either D: Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 10, 2007 Share Posted November 10, 2007 thats cause i made a mistake lol some of the coding jumped down to another row as i copied it from my old code editor so i've put the code again and then a zip with the source code in that i just tested here and it worked saved and all <html><head><title></title></head><body> <font size="4"> <script language=javascript> <!-- function greeting() { Now = new Date() Hour = Now.getHours(); if (Hour < 5) msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 align=middle border=4/>" else if(Hour <12) msg ="<img src=image/main/sunrise.jpg alt=Good morning. width=599 height=488 hspace=30 align=middle border=4/>" else if(Hour < 18) msg ="<img src=image/main/day.jpg alt=Good afternoon. width=599 height=488 hspace=30 align=middle border=4/>" else if (Hour < 24) msg ="<img src=image/main/evening.jpg alt=Good evening. width=599 height=488 hspace=30 align=middle border=4/>" return( msg ) } document.write(greeting()) //--> </script> </font> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
deed02392 Posted November 10, 2007 Author Share Posted November 10, 2007 Thank you very much for that one. The PHP one I had was working but of course was only basing the image on the server time, not the local visitor time. This javascript version is much better as I have frequent visitors from across the globe to my website, so server time doesn't suffice Thanks a lot! Quote Link to comment Share on other sites More sharing options...
smithygotlost Posted November 10, 2007 Share Posted November 10, 2007 nice to know i do help glad to hear it mate email me : mike@theblackmagic.co.uk if you want more help 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.