# dj image changer



## djultra89 (Oct 4, 2012)

hi i'm new to this forum but i have a question
me and my mates run a radio station?
and i'm trying to look for some sort of code 
were the image changes from autodj to one of our dj's?
so for example at 2pm till 7pm is dj solaris then from 
7pm to 12am is autodj then from 12am till 4pm is dj foxy and so forth 
i have a code that will do this but i can't fit it on our home page on the right hand side 
here is our website http://nrgrxtreme.co.uk if you look were the autodj picture is you'll see what i mean


----------



## etaf (Oct 2, 2003)

i have moved to the web design & development forum, you should get more help there - also the link does not work


----------



## djultra89 (Oct 4, 2012)

do you have a link for that department mate


----------



## Ent (Apr 11, 2009)

You're in it. 
The question is where's the link to your website.

Also, are you looking for a PHP script or a javascript script?
Essentially, does the image just have to be picked when the site is loaded? Or should it automatically change if the user remained on that page from say 6:55 to 7:05 PM?


----------



## djultra89 (Oct 4, 2012)

im looking for a php script and it should change automatically


----------



## Ent (Apr 11, 2009)

You can't have both. 
Well, you can't have pure PHP and have it automatically change. PHP runs on the server. It doesn't know what has happened to the client computer; they could have navigated away, closed their browser, even shut down the machine. Javascript, because it is running on the client computer, is able to do fancier stuff like changes to the page once it's already loaded.

You could have PHP to pick the page and javascript to refresh it at the appropriate time, or in theory you could even have php to make the javascript. I'm not sure how you'd pull that one off though.


----------



## djultra89 (Oct 4, 2012)

ok i'll have java script instead? that would be a lot of help as it does fancy stuff 
so would javascript do the job that i'm looking for?


----------



## allnodcoms (Jun 30, 2007)

You can do this (reasonably accurately) in Javascript.
Set up a 24 element array, where each element is the URI of an image. 
When the page loads, find the hour as a value from 0-23, store it, then go to your array and set the image's source attribute to the corresponding array element. Then set up a timeout function to check the current hour against the stored one. If it's different then change the image, then reset the timeout...

Danny


----------



## djultra89 (Oct 4, 2012)

ok but i have a code in php see but i do not know how to work the bottom bit of the code? 
and i don't want the code to push things down on my website see here 
http://www.kprs.com/ <<<<<< thats not my website but if you look were it says on air now 
that images changes one after another? but my website is http://www.nrgextreme.co.uk <<<<< thats my website

but the following code is here

<?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;

// MONDAY SCHEDULE
if ($d == 1 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h >= 4 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h >= 8 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h >= 12 && $h < 14) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h >= 14 && $h < 16) $img = 'images/djtaylor.jpg';
else if ($d == 1 && $h >= 16 && $h < 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h >= 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// TUESDAY SCHEDULE
if ($d == 2 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 4 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 8 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 12 && $h < 13) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 13 && $h < 15) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 15 && $h < 17) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 17 && $h < 20) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 2 && $h >= 20) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// WEDNESDAY SCHEDULE
if ($d == 3 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 4 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 8 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 12 && $h < 13) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 13 && $h < 15) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 15 && $h < 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 3 && $h >= 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// THURSDAY SCHEDULE
if ($d == 4 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 4 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 8 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 12 && $h < 13) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 13 && $h < 15) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 15 && $h < 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 4 && $h >= 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// FRIDAY SCHEDULE
if ($d == 5 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 4 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 8 && $h < 10) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 10 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 12 && $h < 13) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 13 && $h < 15) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 15 && $h < 18) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 18 && $h < 20) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 20 && $h < 22) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 5 && $h >= 22) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// SATURDAY SCHEDULE
else if ($d == 6 && $h >= 0 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 4 && $h < 5) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 5 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 8 && $h < 9) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 9 && $h < 10) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 10 && $h < 11) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 11 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 12 && $h < 13) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 13 && $h < 14) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 14 && $h < 15) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 15 && $h < 17) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 17 && $h < 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 19 && $h < 22) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 6 && $h >= 22) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';

// SUNDAY SCHEDULE
else if ($d == 0 && $h >= 0 && $h < 2) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 2 && $h < 4) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 4 && $h < 5) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 5 && $h < 6) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 6 && $h < 8) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 8 && $h < 9) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 9 && $h < 10) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 10 && $h < 11) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 11 && $h < 12) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 12 && $h < 16) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 16 && $h < 17) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 17 && $h < 18) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 18 && $h < 19) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 19 && $h < 21) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 0 && $h >= 21) $img = 'images3/DJ/dj_dog.jpg';
else if ($d == 1 && $h < 0) $img = 'images3/DJ/dj_dog.jpg';
?>












​

i don't understand about this part


----------



## djultra89 (Oct 4, 2012)

danny could you help me with that code please that i have posted in this forum


----------



## Ent (Apr 11, 2009)

I probably won't have the time to take this one on properlly, I'm sure Danny or someone else will be able to help. Just to point out that your link is still wrong. You should still be able to edit it with the orange button in the bottom right corner of your first post.

I assume it should be http://nrgextreme.co.uk/ and you just hit r instead of e by mistake, but your confirmation would be much more reliable than my assumptions.


----------



## allnodcoms (Jun 30, 2007)

djultra89 said:


> i don't understand about this part


The PHP server side stuff loads the variable $img with the correct image based on the day and the hour. The "<?php echo" bit just prints this into your page before that page is sent from the server to the browser.

Because this happens when the page is requested, the image is correct first time round, but as it's done on the server it won't be updated unless you refresh the page, which would play havoc with any streaming audio. Basically, this bit of code is correct - but it won't work in your case...


djultra89 said:


> danny could you help me with that code please that i have posted in this forum


 Just did... 

If you mean can I write it for you then I'm afraid that's a 'no'. I'm more than happy to help people understand this crazy business that we call the web, but this is a support forum, not a script repository.

To update in real time you're going to need to use javascript. You'll need to call a set up function in the onLoad event of your page, this needs to get the date and time and store them. You'll need an array (similar to the PHP one in your post) that holds the image links. You'll also need to create a checking function that gets called at regular intervals. The checking function will get the date and time (as in the set up function) and compare to the stored values. If they're different then it should update the image and stored values. The function should then (whether it updated anything or not) set a timeout to call itself.

Give it a crack and see how you get on. If you've got any more questions then you know where to call...

Danny


----------



## djultra89 (Oct 4, 2012)

hi danny i did give the code a crack but still can't figure out why the code keeps on pushing everyone down on my home page? i would like the image to go were the auto dj pic is now. but yes i don't have a script for javascript in order for that to work. please help me with the javascript or do you happen to have a javascript code?

if you look here http://nrgextreme.co.uk then look were the autodj pic is if the link don't work copy and paste into a browser of you're choice


----------



## djultra89 (Oct 4, 2012)

infact does anyone have a javascript for what i'm looking for


----------



## colinsp (Sep 5, 2007)

Check out Dynamic Drive or Hot Scripts they may have what you need.


----------



## djultra89 (Oct 4, 2012)

do not worry it's now working for me i had to rename my index from html to php if that makes sence? 
so yes the code is now working


----------



## Ent (Apr 11, 2009)

djultra89 said:


> do not worry it's now working for me i had to rename my index from html to php if that makes sense?
> so yes the code is now working


When the server sees a HTML file, it doesn't by default bother to read it. It just sends it straight on to the client browser.
When the server sees a PHP file, it checks it for PHP code to run before sending it down.

Since you have changed the file name, you'll need to go through the rest of your site and check that you don't have a bunch of broken links. For example the "Home" link on the "About Us" page still points to index.html, and gives a 404 error when you try to click on it.


----------



## allnodcoms (Jun 30, 2007)

djultra89 said:


> do not worry it's now working...


But it won't update without a page refresh...

Danny


----------

