/    Sign up×
Community /Pin to ProfileBookmark

help with ‘for loop’

if i have a for loop going like this …

for( $i = 0; $i < 1000; $i++ ){

echo “blah, blah, blah …”;

}

how can i make it pause for a specific amount of seconds
between each loop and ‘echo’ content to the screen before
resuming the for loop?

i was thinking of using javascript to create a timer, but i assume that
as versatile as php is it probably already has a timer function or even better
a for loop function that lets you specify a pause.

i basically want to loop a file of information, live a comma separated list file,
and print to screen after each loop if i find a match without having to wait for the entire loop to complete.

perhaps i can break; the loop each time a match is found, and then restart it again after [x] seconds have elapsed and tell it where to resume the loop at?

thanks for your input.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chestertbMay 11.2007 — You might be able to slow down the speed at which php assembles its html output, but the speed with which it will be drawn will not be constant, and will depend on the user's connection speed and the speed of their browser. Use javascript or css for any effect you want happening on the client machine.
Copy linkTweet thisAlerts:
@TaschenMay 11.2007 — What you are asking for is a function called "sleep".

However, while this will stop the execution of a loop for a given period of time it will also stop the execution of any other script on the page. Worse, it eats cpu cycles.

I'm going to guess that what you are really aiming for is something akin to a scrolling marque but a great deal more user friendly. I.E. you're talking client side presentation as opposed to server side data acquisition.

Use PHP to gather the data and to create an array to be accessed by JS. Use JS to display the contents of each array key for a given period of time. ("settimeout" is the javascript function you're after).
×

Success!

Help @bsmbahamas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...