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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    120
    Thanks
    15
    Thanked 2 Times in 2 Posts

    PHP output to browser.

    Hi,

    Take this sample loop:

    PHP Code:
    for($i 1$i <= 4$i++) {
       print 
    $i."<br>";
       
    sleep(2);

    When you run the above, it will output all numbers at once. How we can print each number to the browser and wait 2 seconds, then print the other one?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,399
    Thanks
    61
    Thanked 535 Times in 522 Posts
    You can try using flush() but be warned it isn't guaranteed to work. Thats because of the way http works.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,523
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    You'll need to use Javascripting for that.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by muneeba9071 View Post
    Hi,

    Take this sample loop:

    PHP Code:
    for($i 1$i <= 4$i++) {
       print 
    $i."<br>";
       
    sleep(2);

    When you run the above, it will output all numbers at once. How we can print each number to the browser and wait 2 seconds, then print the other one?
    http://www.php.net/manual/en/function.flush.php#85382

    Edit: read all the page, in many cases will not work, the best solution was suggested by mlseim, javascript

    best regards
    Last edited by oesxyl; 03-20-2011 at 05:13 AM.


  •  

    Posting Permissions

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