Jump to content

While Loop


Recommended Posts

With this script:

 

<?php
$i=1;
while($i<=5) {
echo "The number is " . $i . "<br />";
$i++;
sleep(3);
}
?>

 

I get:

 

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

 

How can I make this dynamic. For example:

 

First it would get:

 

The number is 1

 

After 3 seconds...

 

The number is 2

 

After 3 seconds...

 

The number is 3

 

.......

Link to comment
Share on other sites

I think what err.. adhbvklwqdbviabjiawdnbij is after, is the text appearing dynamically on the page - i.e. JavaScript. It's very simple to do. Run this and let us know if it's what you're after...

 

<div id="output"></div>

<script type="text/javascript">
    var i = 0;
    var timer = setInterval(function() {
        document.getElementById('output').innerHTML += 'The number is ' + ++i + '<br>';
        if (i == 5) {
            clearInterval(timer);
        }
    }, 3000);
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.