adhbvklwqdbviabjiawdnbij Posted September 8, 2011 Share Posted September 8, 2011 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 https://forums.phpfreaks.com/topic/246704-while-loop/ Share on other sites More sharing options...
TOA Posted September 8, 2011 Share Posted September 8, 2011 *edit* didn't read full post So you're just not getting the time between echo's? Link to comment https://forums.phpfreaks.com/topic/246704-while-loop/#findComment-1266837 Share on other sites More sharing options...
litebearer Posted September 8, 2011 Share Posted September 8, 2011 perhaps this may help... http://www.webmasterworld.com/php/3554664.htm Link to comment https://forums.phpfreaks.com/topic/246704-while-loop/#findComment-1266841 Share on other sites More sharing options...
voip03 Posted September 8, 2011 Share Posted September 8, 2011 1.Your code works fine 2 After 3 seconds...it will not make any different, make it at least 30sec. http://www.plus2net.com/php_tutorial/sleep.php Link to comment https://forums.phpfreaks.com/topic/246704-while-loop/#findComment-1266842 Share on other sites More sharing options...
Adam Posted September 8, 2011 Share Posted September 8, 2011 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 https://forums.phpfreaks.com/topic/246704-while-loop/#findComment-1266848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.