Click to See Complete Forum and Search --> : how to delay loop?


johnix
06-16-2007, 02:42 AM
i have try to make this code

$temp = 1;
while ($temp<=10) {
echo $temp;
sleep(1);
$temp = $temp + 1;
}


what happen is after 10 seconds, it prints 1-10 all at once... what i want to happen is every loop it will take one second and loop again and the $temp will display every 1 second.

jasonahoule
06-16-2007, 04:43 AM
You need to use flush() to send the output to the browser.

johnix
06-16-2007, 04:54 AM
i already try that like this

$temp = 1;

while ($temp<=10) {
flush();
sleep(1);
dis($temp);
$temp++;;
}


function dis($kuha) {
echo $kuha;
}


but its just the same effect..

jasonahoule
06-16-2007, 04:56 AM
<?php
$temp = 1;
while ($temp<=10) {
echo $temp."<br/>";
flush();
sleep(1);
$temp++;
}

?>

johnix
06-16-2007, 05:05 AM
it just print the numbers vertical... what i want is in every 1 second the number prints.. example for the first loop it will display 1, after 1 second it will loop again to display number 2 and so on.. is there a way to do that?...

jasonahoule
06-16-2007, 05:10 AM
So you are saying that the 1 will no longer be there when the 2 is sent to the page? If that is what you are trying to do then you need to use javascript. I am assuming your intent is not to write out a number so I am not really sure how to help you. You are currently dealing with a single request. Your php code is building that request. So all 10 numbers will be displayed.

johnix
06-16-2007, 05:31 AM
no.. the 1 should also there when the 2-10 numbers print...
first loop print 1
second loop print 2 and it should be like this "12...10". just like in vb or other programing language if you use timer on it.. im trying to find code for that because i want use it in loading several flash movie or .swf.. when the first animation ends then it will give siganl to php to load another .swf or flash movie at the top of the current .swf or flash movie in the page using loop... or if there are any other way that you know, can you share it to me?

jasonahoule
06-16-2007, 09:04 AM
Like was said in the other post, it may be your server configuration. I would suggest using javascript to make asynchronous requests for your swf assets. Put them in a loop so when one finishes the next one starts. The only problem with this approach is the fact that http will limit you to only 2 active requests.

johnix
06-16-2007, 09:26 AM
yeah... i already shifted to javaScript and use timer and interval so that ican manage the loading of swf... thanks for your time...