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
  1. #1
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Problems with strings...

    Look at http://f1unleashed.geoffers.uni.cc/c...hp?race=monaco

    The line of the script is
    PHP Code:
    countdown("print $strYear","print $strMonth","print $strDay","print $strHour","print $strMinute"); 
    In the page it has
    PHP Code:
     $strYear '2004';
     
    $strMonth '5';
     
    $strDay '23';
     
    $strHour '5';
     
    $strMinute '0'

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Can you post the countdown function code?

  • #3
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    PHP Code:
       <?php
    // countdown function
    // parameters: (year, month, day, hour, minute)
    countdown("print $strYear","print $strMonth","print $strDay","print $strHour","print $strMinute");

    //--------------------------
    // author: Louai Munajim
    // website: [url]www.elouai.com[/url]
    //
    // Note:
    // Unix timestamp limitations 
    // Date range is from 
    // the year 1970 to 2038
    //--------------------------
    function countdown($year$month$day$hour$minute)
    {
      
    // make a unix timestamp for the given date
      
    $the_countdown_date mktime($hour$minute0$month$day$year, -1);

      
    // get current unix timestamp
      
    $today time();

      
    $difference $the_countdown_date $today;
      if (
    $difference 0$difference 0;

      
    $days_left floor($difference/60/60/24);
      
    $hours_left floor(($difference $days_left*60*60*24)/60/60);
      
    $minutes_left floor(($difference $days_left*60*60*24 $hours_left*60*60)/60);
      
      
    // OUTPUT
      
    echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
      echo 
    "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
    }
    ?>

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    I see, try this...

    PHP Code:
    countdown($strYear,$strMonth,$strDay,$strHour,$strMinute); 

    If you're passing variables to a function, you don't need to "print" them in the parameter list, just type the vars in straight.

    <edit>
    Shouldn't be a space in strMinute. Can't seem to fix the post.
    </edit>

  • #5
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Thanks but is there anyway from stopping it saying:
    Countdown: 0 days 0 hours 0 minutes left
    The code now is
    PHP Code:
    <?php
        
    // countdown function
        // parameters: (year, month, day, hour, minute)
        
    countdown($strYear,$strMonth,$strDay,$strHour,$strMinute);

        
    //--------------------------
        // author: Louai Munajim
        // website: [url]www.elouai.com[/url]
        //
        // Note:
        // Unix timestamp limitations 
        // Date range is from 
        // the year 1970 to 2038
        //--------------------------
        
    function countdown($year$month$day$hour$minute)
        {
          
    // make a unix timestamp for the given date
          
    $the_countdown_date mktime($hour$minute0$month$day$year, -1);

          
    // get current unix timestamp
          
    $today time();

          
    $difference $the_countdown_date $today;
          if (
    $difference 0$difference 0;

          
    $days_left floor($difference/60/60/24);
          
    $hours_left floor(($difference $days_left*60*60*24)/60/60);
          
    $minutes_left floor(($difference $days_left*60*60*24 $hours_left*60*60)/60);
          
          
    // OUTPUT
          
    echo "Countdown: ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
        }
        
    ?>

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't see a problem, so i ran the code and it seems to work.
    (I got : Countdown: 10 days 6 hours 49 minutes left)

    Though i wouldn't do the if ($difference < 0) $difference = 0;
    like that.
    If difference <0 , then i would take the absolute value (abs()) and then print something like " x was ... days ... hours ... minutes ago"
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by raf
    I don't see a problem, so i ran the code and it seems to work.
    (I got : Countdown: 10 days 6 hours 49 minutes left)

    Though i wouldn't do the if ($difference < 0) $difference = 0;
    like that.
    If difference <0 , then i would take the absolute value (abs()) and then print something like " x was ... days ... hours ... minutes ago"
    How (my knowledge of PHP is still very limited)?

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $difference $the_countdown_date $today;
    $absolute_difference abs($difference);

    $days_left floor($absolute_difference/60/60/24);
          
    $hours_left floor(($absolute_difference $days_left*60*60*24)/60/60);
          
    $minutes_left floor(($absolute_difference $days_left*60*60*24 $hours_left*60*60)/60);

     
    // OUTPUT
    if ($difference != $absolute_difference){
          
    $output'The event was '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' ago !';
    } else {
          
    $output'Countdown: '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' minutes left.';
    }
    echo 
    $output
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Still showing errors, code now is:
    PHP Code:
    <?php
        
    // countdown function
        // parameters: (year, month, day, hour, minute)
        
    countdown($strYear,$strMonth,$strDay,$strHour,$strMinute);

        
    //--------------------------
        // author: Louai Munajim
        // website: [url]www.elouai.com[/url]
        //
        // Note:
        // Unix timestamp limitations 
        // Date range is from 
        // the year 1970 to 2038
        //--------------------------
        
    function countdown($year$month$day$hour$minute)
        {
          
    // make a unix timestamp for the given date
          
    $the_countdown_date mktime($hour$minute0$month$day$year, -1);

          
    // get current unix timestamp
          
    $today time();

    $difference $the_countdown_date $today
    $absolute_difference abs($difference); 

    $days_left floor($absolute_difference/60/60/24); 
          
    $hours_left floor(($absolute_difference $days_left*60*60*24)/60/60); 
          
    $minutes_left floor(($absolute_difference $days_left*60*60*24 $hours_left*60*60)/60); 

     
    // OUTPUT 
    if ($difference != $absolute_difference){ 
          
    $output'The event was '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' ago !'
    } else { 
          
    $output'Countdown: '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' minutes left.'

    echo 
    $output;
        }
        
    ?>




    What's it done... Fixed
    Last edited by gsnedders; 05-13-2004 at 06:47 PM.


  •  

    Posting Permissions

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