Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-06-2013, 12:00 AM   PM User | #1
djultra
New Coder

 
Join Date: Mar 2013
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
djultra is an unknown quantity at this point
Smile coding

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

PHP Code:
<?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 == && $h >= && $h 4$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 14$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 14 && $h 16$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 16 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// TUESDAY SCHEDULE
if ($d == && $h >= && $h 4$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 13$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 13 && $h 15$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 15 && $h 17$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 17 && $h 20$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 20$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// WEDNESDAY SCHEDULE
else if ($d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 22 && $h 00$img 'images2/dj/images/djultra.jpg';
else if (
$d == && $h >= && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 13$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 13 && $h 15$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 15 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// THURSDAY SCHEDULE
if ($d == && $h >= && $h 4$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 16 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 13 && $h 15$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 15 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// FRIDAY SCHEDULE
if ($d == && $h >= && $h 4$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 10$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 10 && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 13$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 13 && $h 15$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 15 && $h 18$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 18 && $h 20$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 20 && $h 22$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 22$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// SATURDAY SCHEDULE
else if ($d == && $h >= && $h 22$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 22 && $h 00$img 'images2/dj/images/djultra.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 9$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 10$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 10 && $h 11$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 11 && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 13$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 13 && $h 14$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 14 && $h 15$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 15 && $h 17$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 16 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 19 && $h 22$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 22$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';

// SUNDAY SCHEDULE
else if ($d == && $h >= && $h 2$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 4$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 5$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 6$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 8$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 9$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= && $h 10$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 10 && $h 11$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 11 && $h 12$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 12 && $h 16$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 16 && $h 17$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 17 && $h 18$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 18 && $h 19$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 19 && $h 21$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h >= 21$img 'images2/dj/images/autodj.jpg';
else if (
$d == && $h 0$img 'images2/dj/images/autodj.jpg';
?>

<html>
<head></head>
<body>
<p align="center"><img src="<?php echo $img?>"> </p>
</body>
</html>
<p>&nbsp;</p>
if anyone could help out that would be great :

Last edited by VIPStephan; 03-06-2013 at 04:10 AM.. Reason: properly added code BB tags
djultra is offline   Reply With Quote
Old 03-06-2013, 01:49 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
This really needs to be moved to the JavaScript forum, I think.

And how come all the images are identical? What's the point in having the code if you don't change the image????
__________________
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.
Old Pedant is offline   Reply With Quote
Old 03-06-2013, 10:22 AM   PM User | #3
djultra
New Coder

 
Join Date: Mar 2013
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
djultra is an unknown quantity at this point
because no one is DJ'ing at the moment were in the process
of sorting new images out for our new radio station is why lol
djultra is offline   Reply With Quote
Old 03-06-2013, 02:07 PM   PM User | #4
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,046
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
Where you write the image to the page you have it mildly wrong. What you want to do is this:

<img src='<$ ...>'>

Putting the string in quotes. A couple of the days have mistakes in the PHP, but you can fix those when the major problem is fixed. Do you have a link? What I would do is look at the page (which happens after the PHP magic happens) to see how that image tag is getting populated.
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 03-07-2013, 01:32 AM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Lightbulb

You can put your PHP code back into this example, but I saw no particular need for it using JS only.

Note your logic can be vastly compressed with a bit of forethought...
The value of $h (hours) can only be withing 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.

Also, you only need to check for the day once and not each and every time.

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...
Code:
<html>
<head>
<title> DJ times </title>
</head>
<body>
<div id="DJtimes">
 <img id="DJpix" src="" title='No show' alt="No show" style="font-size:3em; background-color:orange">
</div>

<script type="text/javascript">
function DJdisplay() {
 var now = new Date();
 var $d = now.getDay();

 var $h = now.getHours();  // adjust for MST if necessary or use UTC time
// var $h = now.getMinutes();  // for testing purposes only before hh:24

 var $year = now.getFullYear();

 var baseURL = 'http://www.nova.edu/hpd/otm/pics/4fun/';  // change to: './images2/dj/images/
 var $img = document.getElementById('DJpix');

/*
 $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;
*/

 if ($d == 1) {  // MONDAY SCHEDULE
       if ($h < 4) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'11.jpg'
  else if ($h < 12) $img.src = baseURL+'12.jpg'
  else if ($h < 14) $img.src = baseURL+'13.jpg'
  else if ($h < 16) $img.src = baseURL+'13.jpg'
  else if ($h < 19) $img.src = baseURL+'14.jpg'
  else if ($h >= 19) $img.src = baseURL+'15.jpg';
 }

 if ($d == 2) {  // TUESDAY SCHEDULE
       if ($h < 4) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'21.jpg'
  else if ($h < 12) $img.src = baseURL+'22.jpg'
  else if ($h < 13) $img.src = baseURL+'23.jpg'
  else if ($h < 15) $img.src = baseURL+'23.jpg'
  else if ($h < 17) $img.src = baseURL+'24.jpg'
  else if ($h < 20) $img.src = baseURL+'25.jpg'
  else if ($h >= 20) $img.src = baseURL+'21.jpg';
 }

 if ($d == 3) {  // WEDNESDAY SCHEDULE
       if ($h < 4) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'31.jpg'
  else if ($h < 12) $img.src = baseURL+'32.jpg'
  else if ($h < 13) $img.src = baseURL+'33.jpg'
  else if ($h < 15) $img.src = baseURL+'33.jpg'
  else if ($h < 17) $img.src = baseURL+'34.jpg'
  else if ($h < 20) $img.src = baseURL+'35.jpg'
  else if ($h >= 20) $img.src = baseURL+'31.jpg';
 }

 if ($d == 4 ) {  // THURSDAY SCHEDULE
       if ($h < 4) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'41.jpg'
  else if ($h < 12) $img.src = baseURL+'42.jpg'
  else if ($h < 13) $img.src = baseURL+'43.jpg'
  else if ($h < 15) $img.src = baseURL+'43.jpg'
  else if ($h < 17) $img.src = baseURL+'44.jpg'
  else if ($h < 20) $img.src = baseURL+'45.jpg'
  else if ($h >= 20) $img.src = baseURL+'41.jpg';
 }

 if ($d == 5) {  // FRIDAY SCHEDULE
       if ($h < 4) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'51.jpg'
  else if ($h < 12) $img.src = baseURL+'52.jpg'
  else if ($h < 13) $img.src = baseURL+'53.jpg'
  else if ($h < 15) $img.src = baseURL+'53.jpg'
  else if ($h < 17) $img.src = baseURL+'54.jpg'
  else if ($h < 20) $img.src = baseURL+'55.jpg'
  else if ($h >= 20) $img.src = baseURL+'51.jpg';
 }

 if ($d == 6) {  // SATURDAY SCHEDULE
       if ($h < 5) $img.src = baseURL+''
  else if ($h < 8) $img.src = baseURL+'11.jpg'
  else if ($h < 9) $img.src = baseURL+'21.jpg'
  else if ($h < 10) $img.src = baseURL+'31.jpg'
  else if ($h < 11) $img.src = baseURL+'41.jpg'
  else if ($h < 12) $img.src = baseURL+'51.jpg'
  else if ($h < 13) $img.src = baseURL+'11.jpg'
  else if ($h < 14) $img.src = baseURL+'21.jpg'
  else if ($h < 15) $img.src = baseURL+'31.jpg'
  else if ($h < 17) $img.src = baseURL+'41.jpg'
  else if ($h < 19) $img.src = baseURL+'51.jpg'
  else if ($h < 22) $img.src = baseURL+'11.jpg'
  else if ($h >= 22) $img.src = baseURL+'21.jpg';
 }

 if ($d == 0) { // SUNDAY SCHEDULE
       if ($h < 2) $img.src = baseURL+''
  else if ($h < 4) $img.src = baseURL+'11.jpg'
  else if ($h < 5) $img.src = baseURL+'21.jpg'
  else if ($h < 6) $img.src = baseURL+'31.jpg'
  else if ($h < 8) $img.src = baseURL+'41.jpg'
  else if ($h < 9) $img.src = baseURL+'51.jpg'
  else if ($h < 10) $img.src = baseURL+'11.jpg'
  else if ($h < 11) $img.src = baseURL+'21.jpg'
  else if ($h < 12) $img.src = baseURL+'31.jpg'
  else if ($h < 16) $img.src = baseURL+'41.jpg'
  else if ($h < 17) $img.src = baseURL+'51.jpg'
  else if ($h < 18) $img.src = baseURL+'11.jpg'
  else if ($h < 19) $img.src = baseURL+'21.jpg'
  else if ($h < 21) $img.src = baseURL+'31.jpg'
  else if ($h >= 21) $img.src = baseURL+'41.jpg';
 }
}

window.onload = function () {
  DJdisplay();
  var interval = 60*60*1000;  // 1 hour checks
//  var interval = 60*100;      // 1 minute checks for testing purposes only
  var t = setInterval("DJdisplay()",interval);
}
</script>

</body>
</html>
jmrker is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:54 AM.


Advertisement
Log in to turn off these ads.