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 12 of 12
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    display a image for afternoon, morning, night

    Hi there,

    here's a easy one i hope, i want to display a image for good morning, good afternoon and good evening based on the time. cant find a script that does this as they all just deal with echoing text rather than a image. if anyone knows of a script for this could you help me out? thanks!

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    they all just deal with echoing text rather than a image
    Just replace the text with the image code.

    Edit: posted wrong code
    Last edited by degsy; 12-31-2005 at 06:03 PM.

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks degsy your a absolute star, just a quick question, after i make my separate php page with the code you gave me, whats the line of code to insert it into the html?

    thanks mate

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The full php file could be

    PHP Code:
    <?php
    $time 
    date("H:i:s");

    if(
    $time '00:00:00' && $time '12:00:00'){
        
    $msg 'Good morning';
        
    $img 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
    }
    elseif(
    $time '12:00:00' && $time '18:00:00'){
        
    $msg 'Good afternoon';
        
    $img 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
    }
    else{
        
    $msg 'Good evening';
        
    $img 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
    }

    ?>
    <img src="<?php echo $img?>" alt="<?php echo $msg?>" />
    or you could make it into a function and call it.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    function greeting(){

    $time date("H:i:s");

        if(
    $time '00:00:00' && $time '12:00:00'){
            
    $msg 'Good morning';
            
    $img 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
        }
        elseif(
    $time '12:00:00' && $time '18:00:00'){
            
    $msg 'Good afternoon';
            
    $img 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
        }
        else{
            
    $msg 'Good evening';
            
    $img 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
        }

    $greeting "$time - $msg <br><img src=\"$img\" alt=\"$msg\" />";

    return 
    $greeting;
    }
    echo 
    greeting();
    ?>

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok ive made a seperate file called time.php with this code

    PHP Code:
    <?php
    function greeting(){

    $time date("H:i:s");

        if(
    $time '00:00:00' && $time '12:00:00'){
            
    $msg 'Good morning';
            
    $img 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
        }
        elseif(
    $time '12:00:00' && $time '18:00:00'){
            
    $msg 'Good afternoon';
            
    $img 'http://search.msn.co.uk/s/hp/bluesky_logo.gif';
        }
        else{
            
    $msg 'Good evening';
            
    $img 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif';
        }

    $greeting "$time - $msg <br><img src=\"$img\" alt=\"$msg\" />";

    return 
    $greeting;
    }
    echo 
    greeting();
    ?>
    now in my index.html, what do i put to make that line of code work, is it <img src="<?php echo $img; ?>" alt="<?php echo $msg; ?>" />

    i dont think ive got that right

  • #7
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    create a file called greeting.php

    PHP Code:
    <?php 
    $time 
    date("H:i:s"); 

    if(
    $time '00:00:00' && $time '12:00:00'){ 
        
    $msg 'Good morning'
        
    $img 'http://www.google.co.uk/intl/en_uk/images/logo.gif'

    elseif(
    $time '12:00:00' && $time '18:00:00'){ 
        
    $msg 'Good afternoon'
        
    $img 'http://search.msn.co.uk/s/hp/bluesky_logo.gif'

    else{ 
        
    $msg 'Good evening'
        
    $img 'http://us.a1.yimg.com/us.yimg.com/i/us/search/b/syc_logo_2.gif'


    ?> 
    <img src="<?php echo $img?>" alt="<?php echo $msg?>" />
    You will have to change your index file to php.

    index.php
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    whatever other code you want

    <?php
    // put the include code where you want the image to appear 
    include 'greeting.php';
    ?>

    </body>
    </html>

  • #8
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks! that worked great, Just wondering, is the time based on the users computer or the servers? its 19.00 in the uk and its saying good afternoon

  • #9
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP scripts are server side and so take the Servers time.
    You can alter the time accordingly.
    http://uk2.php.net/manual/en/function.date.php
    http://uk2.php.net/gmdate


    To use the users time you would have to use javascript or submit grab locational information from their browser.

  • #10
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok ive got a idea, is it possible to find out the time on my server? cos if it is then, i can adjust the times in the scripts by how many hours ahead/behind it is in the uk!!

    er does that sound right?

  • #11
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    echo date('H:i:s'); 
    That'll help.

  • #12
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by muggzy
    ok ive got a idea, is it possible to find out the time on my server? cos if it is then, i can adjust the times in the scripts by how many hours ahead/behind it is in the uk!!

    er does that sound right?
    PHP scripts are server side and so take the Servers time.
    You can alter the time accordingly.
    http://uk2.php.net/manual/en/function.date.php
    http://uk2.php.net/gmdate
    PHP Code:
    <?
    $time 
    date('H:i:s'strtotime('-5 hours'));
    echo 
    $time;
    ?>


  •  

    Posting Permissions

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