Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Count Up Script?

  1. #1
    Join Date
    May 2012
    Posts
    13
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Count Up Script?

    Hey I searched a lot on Google and many other places but couldn't find what i want... It's simple..

    I need a count up script for football that starts counting on a certain date i add... after it starts counting from 0' mins until 45' after that i want it to show a word "Half Time"...
    if possible in the same script after 15 mins the script start counting from 45' to 90' after it reach minute 90 i want it to write "Finished" and stop..
    but please i want it to keep counting even if i refresh the page not start over or something like that..
    if making the script start counting again from 45 to 90 after 15 mins is impossible to do it then its ok with a script to count from 0 to 45 then show "HalfTime" and a script to count from 45 to 90 and show "Finished"

    answers and help are much appreciated really!!!!! i found tons of coupt up scripts but couldn't be able to get it in the way i want coz of my lack in Javascript

    Thanks in Advance!!!
    Last edited by F0u4d; 05-26-2012 at 06:32 AM.

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

    Default

    Why do you say both PHP and Javascript? Javascript can interact with the user (and count by itself), but PHP operates only on the server, so it's for things like interacting with a database.

    Is this for a computer game? If so, it can work. But if this is for a real football game, the clock won't be accurate because of TV breaks for commercials, time outs, and other pauses in the game.

    This is certainly possible, but some of the details need to be worked out.
    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

  3. #3
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Here's my effort:

    Javascript (timer.js):

    PHP Code:
    // Class: Timer
    var Timer = function (callback) {
        
    // Property: Frequency of elapse event of the timer in milliseconds
        
    this.Interval 1000;

        
    // Property: Whether the timer is enable or not
        
    this.Enable = new Boolean(false);

        
    // Event: Timer tick
        
    this.Tick callback;

        
    // Member variable: Hold interval id of the timer
        
    var timerId 0;

        
    // Member variable: Hold instance of this class
        
    var thisObject;

        
    // Function: Start the timer
        
    this.Start = function () {
            
    this.Enable = new Boolean(true);

            
    thisObject this;
            if (
    thisObject.Enable) {
                
    thisObject.timerId setInterval(
                function () {
                    
    thisObject.Tick();
                }, 
    thisObject.Interval);
            }
        };

        
    // Function: Stops the timer
        
    this.Stop = function () {
            
    thisObject.Enable = new Boolean(false);
            
    clearInterval(thisObject.timerId);
        };

    };

    // Namespace: Match rules and timings
    var Match = {

        
    Timers: {
            
    FirstHalf: new Timer(TimerTick),
            
    HalfTime: new Timer(TimerTick),
            
    SecondHalf: new Timer(TimerTick),
            
    TickCount: -1
        
    },

        
    Strings: {
            
    FirstHalf'First Half',
            
    HalfTime'Half Time',
            
    SecondHalf'Second Half',
            
    FullTime'Finished'
        
    },

        
    DisplayTime: function (t) {
            var 
    parseInt(60);
            var 
    60;
            return (
    10 '0' m) + ":" + (10 '0' s);
        }
    };

    // Function: Tick Event Handler (callback function)
    function TimerTick(timer) {

        
    // Document elements used.
        
    var TimerP document.getElementById('time');
        var 
    DisplayP document.getElementById('display'); 

        
    // During First Half
        
    if (Match.Timers.FirstHalf.Enable == true) {
            if (
    Match.Timers.TickCount == -1) { Match.Timers.TickCount }
            if (
    Match.Timers.TickCount == 2700) {
                
    Match.Timers.FirstHalf.Stop();
                
    Match.Timers.TickCount = -1;
                
    Match.Timers.HalfTime.Start();
            } else {
                
    TimerP.innerHTML Match.DisplayTime(Match.Timers.TickCount);
                
    DisplayP.innerHTML Match.Strings.FirstHalf;
                
    Match.Timers.TickCount++;
            }
        }

        
    // During Half Time
        
    else if (Match.Timers.HalfTime.Enable == true) {
            if (
    Match.Timers.TickCount == -1) { Match.Timers.TickCount }
            if (
    Match.Timers.TickCount == 900) {
                
    Match.Timers.HalfTime.Stop();
                
    Match.Timers.TickCount = -1;
                
    Match.Timers.SecondHalf.Start();
            } else {
                
    TimerP.innerHTML '45:00';
                
    DisplayP.innerHTML Match.Strings.HalfTime ' (' Match.DisplayTime(900 Match.Timers.TickCount) + ')';
                
    Match.Timers.TickCount++;
            }
        }

        
    // During Second Half
        
    else if (Match.Timers.SecondHalf.Enable == true) {
            if (
    Match.Timers.TickCount == -1) { Match.Timers.TickCount 2700 }
            if (
    Match.Timers.TickCount == 5400) {
                
    TimerP.innerHTML '90:00';
                
    DisplayP.innerHTML Match.Strings.FullTime;
                
    Match.Timers.SecondHalf.Stop();
                
    Match.Timers.TickCount = -1;
            } else {
                
    TimerP.innerHTML Match.DisplayTime(Match.Timers.TickCount);
                
    DisplayP.innerHTML Match.Strings.SecondHalf;
                
    Match.Timers.TickCount++;
            }
        }
    }

    function 
    KickOff() {
        var 
    btn document.getElementById('btnKickOff');
        
    btn.setAttribute('style','display: none;');
        
    Match.Timers.FirstHalf.Start();

    HTML:

    HTML Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!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 runat="server">
            <!-- Start Meta Block -->
            <meta content="text/html; charset=iso-8859-1" http-equiv="content-type" />
            <meta content="Simple Football Match Timer" name="description" />
            <meta content="Simple, Football, Match, Timer" name="keywords" />
            <meta content="all,index,follow" name="robots" />
            <meta content="noodp" name="msnbot" />
            <meta content="global" name="distribution" />
            <!-- End Meta Block-->
            <title>Simple Football Match Timer</title>
            <script src="timer.js" type="text/javascript"></script>
        </head>
    
        <body>
            <form id="pageForm" runat="server">
                <div>    
                    <p id="display">Waiting for kick off.</p>
                    <p id="time">00:00</p>
                    <input id="btnKickOff" type="button" value="Kick Off!" onclick="KickOff();" />
                </div>
            </form>
        </body>
    </html>
    I think it has everything you asked for.
    Last edited by ApacheTech; 05-26-2012 at 04:09 AM.

  4. The Following User Says Thank You to ApacheTech For This Useful Post:

    F0u4d (05-26-2012)

  5. #4
    Join Date
    May 2012
    Posts
    13
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    @djr33 Sorry i wrote PHP by mistake!.. and thanks for explaining for me!.. Well it doesn't matter for me if its in PHP or JS

    ApacheTech Did a great script.. Thanks mate!, but the problem is that i want it to keep counting even when i refresh page... i want users to be able to see what time the match is now during the match... and in fooball theres no commercials, just in during the Halftime which is 15 minutes
    So the script is just great but how can i make it not start over with ever page refresh? Thanks.
    Last edited by F0u4d; 05-26-2012 at 06:55 AM.

  6. #5
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    How would you factor in the injury time and stoppages?

    Is it for live matches IRL?

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

    Default

    Oh, football = soccer, not football = American football. I see. That's easier, but as ApacheTech said, it's not just counting, right? Time outs, for example.

    Using Javascript alone is probably the best approach here. However, you might want to use PHP to originally set the starting number for Javascript when the page loads, if you need it to be the same time when you refresh the page.
    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

  8. #7
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Really, only yanks call american football, football. To most of the planet, football is what the yanks call soccer. Most of the rest of the world calls american football, "Rugby for wimps".

    Don't get me wrong, football is even worse than american football. Never could stand it.

    If you want to simulate a game, this is easier than tracking a live game.

    We could throw in some random events that stop the clock every so often, like players crying because someone came within two feet of them, faked injuries, pathetic goal celebrations and the usual idiocy that goes on.

    You wouldn't need the Timer class in that case though, you'd need a different form of timer that counts from a set time and uses a DateDiff as the Tick.

  9. #8
    Join Date
    May 2012
    Posts
    13
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    @ApacheTech, yes you're right... i forgot about the additional time that gets added at the end of each half by the referee before the 15 mins break starts :/
    I really appreciate your help its a great script!
    but idk how could i make it start on a fixed date and keep counting no matter if i refresh the page

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

    Default

    You could use a cookie to remember the time, or you could use a real-life reference time (for example, 2pm on May 28) or you could store that real-life reference time in PHP and set the Javascript timer relative to that.
    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

  11. #10
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    The only PHP IDE I have available is Visual Studio 2010 with Phalanger installed, but it doesn't seem to be set up right. I couldn't even get DateTime.

    You could set up a class in PHP with random events, timed events, stringlist and everything you need.

    If you're simulating a match, you could have the fixtures list in a database:

    tblTeams
    team_id (Autonumber)
    team_name (String)

    tblFixtures
    fixture_id (Autonumber)
    home_team_id (Lookup: tblTeams.team_id)
    away_team_id (Lookup: tblTeams.team_id)
    fixture_timestamp (DateTime)

    Then you can load each fixture into a Fixture class as an array:

    PHP Code:
    <?php

    class Fixture {

        
    // Private Members
        
    private $m_hometeam;
        private 
    $m_awayteam;
        private 
    $m_kickofftime;

        
    // Constructor
        
    function __construct($_hometeam$_awayteam$_kickofftime) {
           
    $this->m_hometeam $_hometeam;
           
    $this->m_awayteam $_awayteam;
           
    $this->m_kickofftime $_kickofftime;
        }

        
    // Public Properties
        
    public function HomeTeam() {
            return 
    $this->m_hometeam;
        }

        public function 
    AwayTeam() {
            return 
    $this->m_awayteam;
        }

        public function 
    KickOffTime() {
            return 
    date_format($this->m_kickofftime'Y-m-d H:i:s');
        }
    }

    ?>
    PHP Code:
    <?php

    $sql 
    'SELECT T.team_name, F.home_team_id, F.away_team_id, F.fixture_timestamp FROM tblFixtures AS F, tblTeams AS T ORDER BY F.fixture_timestamp';
    $result mysql_query($sql);

    $FixturesList = array();

    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
        
    array_push($FixturesList, new Fixture($row['home_team'], $row['away_team'], $row['fixture_timestamp']));
    }

    ?>
    This is obviously only extremely basic but it'll give you a starting place.

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
  •