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,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 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 04: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
    •