Page 3 of 3 FirstFirst 123
Results 21 to 27 of 27

Thread: Display different image each hour of the day (based on server time)

  1. #21
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    If you have a new question, please start a new thread. Don't interrupt or restart an old discussion with something new-- that's just confusing. (And this advice is intended to get you better help.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #22
    Join Date
    Aug 2013
    Location
    Rio Maior, Portugal
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    If you have a new question, please start a new thread. Don't interrupt or restart an old discussion with something new-- that's just confusing. (And this advice is intended to get you better help.)

    But my question is related to this topic... -.-'

    I just wanna add minutes to the code, since only have days and hours.

    Need to open a new topic for that?

  3. #23
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yes, if you need specific help for your own question that goes beyond this one, it is better to start a new thread. (You will also receive more attention that way, rather than in the old thread here.)
    You can link back to this one as needed.

    But since your question is related and might be simple to solve, let me see if this helps:
    You can add the following code to all of the lines as needed:
    && $m>10
    That means "and it is 10 minutes after the hour". Adjust as needed.

    Does that solve the problem? If you need more help and we need to have a longer conversation, I do recommend a new thread.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #24
    Join Date
    Aug 2013
    Location
    Rio Maior, Portugal
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Yes, if you need specific help for your own question that goes beyond this one, it is better to start a new thread. (You will also receive more attention that way, rather than in the old thread here.)
    You can link back to this one as needed.

    But since your question is related and might be simple to solve, let me see if this helps:
    You can add the following code to all of the lines as needed:
    && $m>10
    That means "and it is 10 minutes after the hour". Adjust as needed.

    Does that solve the problem? If you need more help and we need to have a longer conversation, I do recommend a new thread.
    Hey, thanks for ur reply.

    This is what i'm using:

    Code:
    if ($d == 1 && $h >= 7 && $h < 7 && $m <= 20) { $img = 'images/horario/auto_system.png'; $locutor = 'Radio5'; $hora = '7:00 AM - 7:20 AM'; $text = 'Panorama'; if(mb_strlen($text)>13) { $text=mb_substr($text, 0, 13); $text.='...'; } } 
    
    else if ($d == 1 && $h >= 7 && $m <= 20 && $h < 8) { $img = 'images/horario/delbis_02.png'; $locutor = 'Delbis'; $hora = '7:20 AM - 8:00 AM'; $text = 'La Bendicion De La Mañana'; if(mb_strlen($text)>13) { $text=mb_substr($text, 0, 13); $text.='...'; } } 
    
    echo'<div style="float: left; width: 90px"><img src="'.$img.'" height="80px" width="80px" style="border: 1px solid green" /></div><div style="float: left; width: 141px; height: 80px; margin-top: 10px; color: #FFFFFF; font-family: Tahoma; font-size: 15px;">'.$text.' <br \>'.$hora.'<br \> Con: '.$locutor.'</div>';
    How are read this functions?

    If day 1 and hour >= 7 and hour < 7 and minute <= 20 ?

    If day 1 and hour >= 7 and minute <=20 and hour < 8 ?

    But it work for this 7.00 AM - 7.20 AM and 7:20 AM - 8:00 AM?

    I don't have to group hour with minutes? with () or anything?

    Thanks for your help. I think this is related and topic is old but very usefull.

  5. #25
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It depends on the exactly logic you require. && is symmetrical and doesn't need to have any parentheses.

    $d==1 && $h<12 && $m>10

    That means "if the day is '1' and it's before 12 hours, and it's after 10 minutes..."
    That describes ANY time after 10 minutes past the hour, so... 12:10am, 1:10am, ... 11:10am...

    If you're looking for an exact time, use ==:
    $d==1 && $h==12 && $m>10
    That means 11:10am-11:59am
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #26
    Join Date
    Aug 2013
    Location
    Rio Maior, Portugal
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks you helped a lot.

    I last doubt, is this correct? I want to make 7:20 AM - 9:00 AM

    Code:
    else if ($d == 6 && $h == 7 && $m > 20 && $h < 9) { $img = 'images/horario/auto_system.png'; $locutor = 'Auto'; $hora = '7:20 AM - 9:00 AM'; $text = 'Musica Fin De Semana'; if(mb_strlen($text)>13) { $text=mb_substr($text, 0, 13); $text.='...'; } }
    Thanks.

  7. #27
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For a range like that you'll need to use some parentheses. There are a few ways to do that. One would be to convert the time to something like 0720 0900 and then just check if the number is between those points ($n>720&&$n<900). But you can do it the long way like this:
    if ($d==6 && ($h==8|| ($h==7 && $m>20) ) )

    Note that I'm doing this as exclusive-- the endpoints won't count. So it's from 7:21 to 8:59 inclusive. As needed, you can adjust the rest.

    So you can use parentheses as needed. And ==, <, >, <=, <= for comparison. Then && for 'and' and || for 'or'. That should be everything you need.

    As for the other method, the easiest way is probably to multiply like this:
    $n = $d*10000 + $h*100 + $m;

    That'll give you a number that is in the right sequence, although the actual way that the numbers add up won't make much sense (just like on a clock, it'll skip from 959 to 1000 etc.).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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