Looking to hire a PHP programmer...

Discussion in 'Programming' started by thetismedia, Jul 21, 2011.

  1. #1
    Hi, I am working on a schedule and need help finishing it. I've got an image that needs to be replaced according to certain times of the day/week. So far, I've got the image changing properly on the hour BUT as soon as I try to make the switch on a specific minute, the script breaks. There are no errors, the image just doesn't load. I would be happy to pay anyone who can help for their time and possibly send more work in the future. Here's where I'm at now:

    <?php

    $h = date('G'); //create a variable called $h to define to the hour of the day.
    $m = date('i'); //create a variable called $m to define to the minute of the hour.
    $d = date('w'); //create a variable called $d to the define to the day of the week.
    $year = date('Y'); //create a variable called $year to define to the current year.
    // Note that the hours are in a 24 hour format.
    // Adjust the UTC offset to the timezone your SERVER uses.
    $h = $h-0;
    // MONDAY SCHEDULE
    if ($d == 1 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 1 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 1 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 1 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 1 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 1 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 1 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 1 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 1 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 1 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 1 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 1 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 2 && $h < 0) $img = 'images/pic1.jpg';
    // TUESDAY SCHEDULE
    if ($d == 2 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 2 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 2 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 2 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 2 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 2 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 2 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 2 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 2 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 2 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 2 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 2 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 3 && $h < 0) $img = 'images/pic1.jpg';
    // WEDNESDAY SCHEDULE
    if ($d == 3 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 3 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 3 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 3 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 3 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 3 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 3 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 3 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 3 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 3 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 3 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 3 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 4 && $h < 0) $img = 'images/pic1.jpg';
    // THURSDAY SCHEDULE
    if ($d == 4 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 4 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 4 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 4 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 4 && $h >= 7 && $h < 14) $img = 'images/pic5.jpg';
    else if ($d == 4 && $h >= 14 && $h < 15) $img = 'images/pic6.jpg';
    else if ($d == 4 && $h >= 15 && $h < 20) $img = 'images/pic7.jpg';
    else if ($d == 4 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 4 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 5 && $h < 0) $img = 'images/pic1.jpg';
    // FRIDAY SCHEDULE
    if ($d == 5 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 5 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 5 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 5 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 5 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 5 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 5 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 5 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 5 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 5 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 5 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 5 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 6 && $h < 0) $img = 'images/pic1.jpg';
    // SATURDAY SCHEDULE
    if ($d == 6 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 6 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 6 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 6 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 6 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 6 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 6 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 6 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 6 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 6 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 6 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 6 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 7 && $h < 0) $img = 'images/pic1.jpg';
    // SUNDAY SCHEDULE
    if ($d == 7 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    else if ($d == 7 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    else if ($d == 7 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    else if ($d == 7 && $h >= 6 && $h < 7) $img = 'images/pic4.jpg';
    else if ($d == 7 && $h >= 7 && $h < 11) $img = 'images/pic5.jpg';
    else if ($d == 7 && $h >= 11 && $h < 13) $img = 'images/pic6.jpg';
    else if ($d == 7 && $h >= 13 && $h < 15) $img = 'images/pic7.jpg';
    else if ($d == 7 && $h >= 15 && $h < 17 && $m > 30) $img = 'images/pic8.jpg';
    else if ($d == 7 && $h >= 17 && $m > 30 && $h < 19 && $m > 30) $img = 'images/pic9.jpg';
    else if ($d == 7 && $h >= 19 && $m > 30 && $h < 20) $img = 'images/pic10.jpg';
    else if ($d == 7 && $h >= 20 && $h < 22) $img = 'images/pic11.jpg';
    else if ($d == 7 && $h >= 20) $img = 'images/pic12.jpg';
    else if ($d == 1 && $h < 0) $img = 'images/pic1.jpg';
    ?>

    <html>
    <head></head>
    <body>
    <img src="<?php echo $img; ?>" border="none">
    </body>
    </html>
     
    thetismedia, Jul 21, 2011 IP
  2. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    I didn't give the script much inspecting, but its coded poorly to begin with, no offence, Lol. Seems like your time variables are storing inaccurate data from those time functions you're using. In PHP its very easy to troubleshoot for errors. To begin troubleshooting, I'll output the data being stored in the time variables using the echo/print command to see if they are accurate which I doubt.

    e.g. Somewhere in the code, preferably underneath the line "// MONDAY SCHEDULE", I'd put:
    echo 'Hour: '.$h.'<br/>Month: '.$m.'<br/>Date: '.$d.'<br/>Year: '.$year;

    From there, you'd see if the data is accurate, cuz I doubt it is. If that's not the problem, then it may be your if/else logic.
     
    Andre91, Jul 25, 2011 IP
  3. Rufas

    Rufas Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #3
    Just gone through them. Indeed, it is if/else logic problem. If you use Day 1 4:41am (or 0441), this is what happens:

    if ($d == 1 && $h >= 0 && $h < 1) $img = 'images/pic1.jpg';
    // $h < 1 means not matched
    else if ($d == 1 && $h >= 1 && $h < 5 && $m > 42) $img = 'images/pic2.jpg';
    // $h < 5 matches, but $m > 42 not match
    else if ($d == 1 && $h >= 5 && $m > 42 && $h < 6) $img = 'images/pic3.jpg';
    ... code...
    // nothing matches $d == 1, $h == 4 and $m == 41 from this point onwards

    No wonder the image doesn't load.

    - Rufas

    P.S. If you still need help on this script, contact me.
     
    Rufas, Aug 1, 2011 IP
  4. SpiderHunter

    SpiderHunter Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If I were you I would try freelancer or odesk.
     
    SpiderHunter, Aug 2, 2011 IP