+ Reply to Thread
Results 1 to 8 of 8

 

Thread: simple countdown script needed

  1. #1
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    797
    Thanks
    16
    Thanked 19 Times in 16 Posts


    hey guys

    ok im pullin my hair out over this

    anyone able to knock up a quick countdown script

    basically the page would effectivly refresh and then decrease the seconds , minutes , hours as needed

    ive tried it but cant seem to get it to work

    there would be 3 variables

    hrs , min , sec
    these are initially defined by the values in the database
    so lets assume
    $hrs = ' 08';
    $min = '47';
    $sec = '03';


    now what i tried to do is to check on reload to see if sec == 0 then min - 1 then set sec to 59
    e.g.
    PHP Code:
    $sec $sec '1';
    if(
    $sec == '00'){
    $sec '59';
    $min 1;
    }
    if(
    $min == '00'){
    $hrs -1;
    $min '59';
    }
     if(
    $hrs== '00' && $min == '00' && $sec == '00') { 
    do 
    this code here 

    im also using a simple meta refresh at the top of the page

    anyone able to shed some light on thisannoying situation
    High Quality Bed Frames From BedFrames.co.uk
    bed frames

  2. #2
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    152
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Hi,

    This appears to be what you are after, all it needs is a little editing of the output to make the countdown look how you want. Also would probably be pretty easy to convert it into an ajax call that would update within the page without the need for refresh. Allowing you to have a live countdown changing in front of peoples eyes as if by magic!

    WLScripting.com Countdown to a time

  3. #3
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    797
    Thanks
    16
    Thanked 19 Times in 16 Posts
    must be daft lol but i cant see where to define teh time i want it to countdown too
    High Quality Bed Frames From BedFrames.co.uk
    bed frames

  4. #4
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    152
    Thanks
    2
    Thanked 5 Times in 5 Posts
    you'd put a bit of php in your page something like this:

    <?php

    $testTime = strtotime("25 December 2008");
    echo timeLeft($testTime).'<br>';
    ?>

    or you could use mktime instead of strtotime if you wanted a more specific date to count down to e.g.

    <?php
    $testTime = mktime(23, 59, 59, 12, 24, 2008);
    echo timeLeft($testTime).'<br>';
    ?>

    mktime variable order: hour, minute, second, month, day, year

  5. #5
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    797
    Thanks
    16
    Thanked 19 Times in 16 Posts
    ahh cheers

    was havin a dumb moment then
    High Quality Bed Frames From BedFrames.co.uk
    bed frames

  6. #6
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    797
    Thanks
    16
    Thanked 19 Times in 16 Posts
    getting

    Warning: Missing argument 1 for timeLeft(), called in D:\wamp\www\countdown.php on line 41 and defined in D:\wamp\www\countdown.php on line 4
    PHP Code:
    $theTime mktime(20010011122008);

    function 
    timeLeft($theTime) {

      
    $now strtotime("now");
      
    $timeLeft $theTime $now;
      
      if(
    $timeLeft 0) {
        
    $days floor($timeLeft/60/60/24);
        
    $hours $timeLeft/60/60%24;
        
    $mins $timeLeft/60%60;
        
    $secs $timeLeft%60;
        
        if(
    $days) {
          
    $theText $days " Day(s)";
          if(
    $hours) {
            
    $theText .= ", " .$hours " Hour(s) ";
          }
        } elseif(
    $hours) {
          
    $theText $hours " Hour(s)";
          if(
    $mins) {
            
    $theText .= ", " .$mins " Minute(s) ";
          }
        } elseif(
    $mins) {
          
    $theText $mins " Minute(s)";
          if(
    $secs) {
            
    $theText .= ", " .$secs " Second(s) ";
          }
        } elseif(
    $secs) {
          
    $theText $secs " Second(s)";
        }
      } else {
        
    $theText "The countdown is over!";
      }

      return 
    $theText;

    High Quality Bed Frames From BedFrames.co.uk
    bed frames

  7. #7
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    152
    Thanks
    2
    Thanked 5 Times in 5 Posts
    No problem, im one permanent blonde moment

    The issue you seem to be having is that you aren't passing $theTime to the timeLeft function. When you call timeLeft in your page you need to call it timeLeft($theTime).

    or if you are doing this I have just noticed that you have a variable $timeLeft within your function timeLeft, this could potentially be causing a naming conflict so just in case I would change the variable within the function to something like $time_left.

    Hope that helps.

  8. #8
    Registered User

    Status
    Offline
    Join Date
    May 2008
    Posts
    797
    Thanks
    16
    Thanked 19 Times in 16 Posts
    DOH !

    yeah that was it lol

    was calling timeLeft() instead of timeLeft($theTime)

    in the words of del boy .. what a plonker !
    you seem to know yoru stuff..

    check out my other thread in the php help section .. you might be interested
    High Quality Bed Frames From BedFrames.co.uk
    bed frames

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Countdown script for Wordpress
    By laurawp in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 06-11-07, 07:56 PM
  2. WANTED - Simple Feedback / Comments Script
    By purple in forum Programming
    Replies: 1
    Last Post: 04-01-07, 04:32 PM
  3. 67 Datafeed website scripts
    By Leeky in forum Programming
    Replies: 0
    Last Post: 28-09-06, 07:56 PM
  4. really simple newlsetter programme needed.
    By Elaine in forum Media Coverage & PR Strategy
    Replies: 8
    Last Post: 29-07-05, 02:51 AM
  5. Popcorn Line Script Help needed
    By scifind in forum Programming
    Replies: 0
    Last Post: 21-03-03, 07:13 PM

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
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2