Results 1 to 3 of 3

Thread: Counter continuing from page to page?

  1. #1
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Counter continuing from page to page?

    Hi,

    I would like to reproduce the counter present in the header of the page http://www.ensembleverslavenir.ca/fr/accueil/

    The calculation code looks easy (check below), but there has a cookies system (or an ASP code that I would like to convert in PHP), which allow the counter to continue from page to page (idem if you did a page refresh).

    Perhaps an ID is created whenever the browser opens a session on the site?
    The counter restarts at zero when the browser leaves the site.

    Would you have an idea of how to re-encode the same system but in PHP?
    Thanks a lot
    Chris


    <div class="counter"><span id="counter">8.15</span> tonnes</strong> de gaz à effet de serre ont été émis au Québec depuis le début de votre visite.</div>

    <script language="JavaScript" type="text/javascript">
    var sTotal = 0;
    function gazCount(){
    sTotal=sTotal+(0.1);
    document.getElementById("counter").innerHTML = r2(sTotal*2.91);
    //document.getElementById("counter").innerHTML = r2(sTotal);
    setTimeout("gazCount();", 100);
    }
    function r2(n){
    ans = n * 1000
    ans = Math.round(ans /10) + ""
    while (ans.length < 3) {ans = "0" + ans}
    len = ans.length
    ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
    return ans
    }
    gazCount();
    </script>

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Would you have an idea of how to re-encode the same system but in PHP?
    The counter is done with Javascript, and it is a dynamic script... PHP only codes "static", I'll say, scripts. You can't make animations with PHP for example.
    - Mike

  3. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    I have a script that usign php/javascript to get the current server's time with PHP but then make an automatic counter so that it keeps going up using javascript.

    I also have one that will retrieve a timestamp from the database, find out how many seconds it is until that, turn it into hh:mm:ss format, and do a countdown, and at the end when it reaches 0:00:00 it refreshes the page.

    Would that help atall?

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
  •