Add number of x per second.

Discussion in 'PHP' started by Zidu, Nov 5, 2008.

  1. #1
    I'm looking for php script which adds a number of x (example 60) and ending each second,
    and the result displays on screen in real time.
    However, the final outcome as in the script js

    Example:
    <p style="float: left;">
    $<div id="start" style="float: left;">1</div>
    </p>
    <script type="text/javascript">var n=1;
    function add(n){
        document.getElementById("start").innerHTML=n;
        n++;
        setTimeout("add("+n+")",100);
    }
    add(n);
    </script>
    
    Code (markup):
    I am able to pay for it.
    Sorry for my English.
     
    Zidu, Nov 5, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Can't really understand what u want?

    If you want to do real-time update using PHP thats impossible.

    We need more explanations & details
     
    ads2help, Nov 5, 2008 IP
  3. SEOAnalytic.com

    SEOAnalytic.com Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Do you want that in ajax, cause that is the only method to show php results "in real time".
     
    SEOAnalytic.com, Nov 5, 2008 IP
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Just use jquery and setinterval (javascript).

    
    <script type="text/javascript">
    setInterval("getAjaxUpdate()",1000);
    function getAjaxUpdate(){
    $("updateResult").load="url_to_your_php_file.php";
    }
    </script>
    <div id="updateResult"></div>
    
    HTML:
     
    elias_sorensen, Nov 5, 2008 IP
  5. Zidu

    Zidu Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So it should be like effect on the screen.
     
    Zidu, Nov 6, 2008 IP
  6. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #6
    you must use ajax on this one, store your variable in a session so it will not restart on refresh..
    add another 0 to your setTimeout function
     
    bartolay13, Nov 6, 2008 IP