Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By jmrker

Thread: coding

  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 05:10 AM. Reason: properly added code BB tags

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    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.

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    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

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 505 Times in 499 Posts

    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>
    djhaystack likes this.

  • #6
    New to the CF scene
    Join Date
    Nov 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would somebody be willing to help with an addition to this? I'd like to add a link to the image, and utilize a different BaseURL for that link in each entry. IE: Base+djImage1.jpg is linked to baseurl.com so I can link to the DJ's webpage.

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    WOW, what an inefficient way to do it. If you're going to do it weekly, all you really need is an array of 168 images.Then just poll through the images and repeat. You just need to have javascript change the src of the image to the next one in the array. Or you could make it more or less than 168 and just make it change every hour. The only trick will be making the image change for a loaded page. You don't even need to change the image name, the indexed ( numbered ) array will cope with that.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #8
    New to the CF scene
    Join Date
    Nov 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I cast my fears aside and tinkered around with this, and got the result I was searching for. More than happy to take input, but here's how I added links to the script:

    I added the following near the top underneath the other variable declarations:

    Code:
    var page = document.getElementById("DJtimes").setAttribute('onclick', 'location.href = $pageurl');
    and then added the variable to the end of each time slot, such as:

    Code:
       if ($h < 21) $img.src = baseURL+'hogcall.png', $pageurl = 'page-url-here'
    I know this might not be just right and is super simple, but I'm proud of myself lol.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,643 Times in 4,605 Posts
    I think I agree with DrDOS on this: Just create the 168-element array so that it is easy to change. And just reference an object that has all the needed info.

    Example:
    Code:
    var people = {
        "none" : { image: "nobody.jpg", url: "", genre: "" },
        "Anne" : { image: "anneJones.jpg", url: "www.anne.net/info.html", genre: "rock" },
        "Bob" : { image: "gorilla.png", url: "www.google.com", genre: "alternative" },
        "Carl" : { image: "carlAdams.jpg", url: "www.people.com/carlAdams", genre: "pop" }
    };
    
    var calendar = [
        /* sunday */
       [ none, none, none, none, none, none, /* midnight to 5am */
         Anne, Anne, Anne, Anne, Anne, Anne, /* 6am to 11am */
         Carl, Anne, Carl, Carl,Carl, Bob, /* noon to 5pm
         Bob, Bob, Bob, Bob, none, none ], /* 6pm to 11pm */
        /* monday */
        ... etc...
    ];
    So now it is easy to change the schedule: You just find the day and the appropriate hour in the calendar array (and sub arrays for each day of the week) and change who is scheduled for that hour. Presto.
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •