If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

on-air script

hi there i would love my images
to change on the hour everytime our DJ'S
come on air, but also would like the page to refresh as well so that
it shows a new image? i know its in php but its the only way it could show on my site
but would like a different code to this one? heres the code

i know it's in php and someone told me that this code would not work!!
but is there some sort of any other on-air scripts

<?php
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
$year = date('Y'); //set variable $year to the current year
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
// Adjust 2 hour offset for MST below.
$h = $h+1;

then on weekends there will be a show together with djultra and dj rabbit
between 4pm and 6pm, GMT

At all other times the display will show autodj.

What I intend to do is have your PHP code send the current time ON THE SERVER out to the browser, so that we don't have to rely on users having their individual computer clocks set correctly. Then I calculate an "error offset" (that is, how much their computer clock disagrees with the server) and from then on use that offset when determining what time it actually is on the server. That way, we only have to send the time from server to client when the page is first loaded. Make sense?

An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

If it doesn't seem to work:
(1) bring up the page in your browser
(2) click on VIEW menu
(3) click on SOURCE or PAGE SOURCE menu item
(4) find the line with var serverTime = ...
(5) copy/paste what you see here to forum.

I don't use PHP, so that one line of PHP code is somewhat of a guess. But if you debug as above, we'll figure it out.

You can put your PHP code back into this example, but I saw no particular need for it using JS only.
I used the setInterval() function to check for changes every hour if the page is open for that length of time.

Note your logic can be vastly compressed with a bit of forethought...
The value of $h (hours) can only be within the range of 0..23 in military time.
Therefore all you need to do is check for $h < hour starting a midnight and staying sequential in your test logic.

Also, you only need to check for the day once and not each and every time.
If the schedule stays the same for any one or more days, the logic could be compressed further.

Substitute your own path and image file names into the appropriate lines
and ask questions about the following logic if it does not make sense to you...