runei Posted April 23, 2009 Share Posted April 23, 2009 I am selecting a field from mysql db in a while statement. What I want is a interval of lets say 1-2 seconds for each printed record. Like a lottery system. How do i go about it? thx runei Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/ Share on other sites More sharing options...
jackpf Posted April 23, 2009 Share Posted April 23, 2009 You couldn't really do that with php, as the page would hang until the script had been parsed. All you'd be doing with a 2 second pause would be making the page hang for longer. You might want to use javascript to reveal a hidden div every two seconds or something though. Edit: Well...I suppose you could do it with output buffering, but it wouldn't be as reliable as javascript. Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817419 Share on other sites More sharing options...
runei Posted April 23, 2009 Author Share Posted April 23, 2009 Ok. thx for the info Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817425 Share on other sites More sharing options...
JonnoTheDev Posted April 23, 2009 Share Posted April 23, 2009 These functions will do what you are after. look them up in the manual for usage. ob_start(); flush(); ob_flush(); Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817433 Share on other sites More sharing options...
jackpf Posted April 23, 2009 Share Posted April 23, 2009 Surely javascript would be more reliable? Fore example, with output buffering, it would only display the page up to the point that had been parsed when you echo the buffer contents. So if you have a footer or something, it won't be displayed until everything else has been. Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817436 Share on other sites More sharing options...
runei Posted April 23, 2009 Author Share Posted April 23, 2009 Personally i am quite ignorant here. I am looking in to both and i'll see what i come up with. This looks pretty much what i am after. havent tested it yet though. <?php if (ob_get_level() == 0) ob_start(); for ($i = 0; $i<10; $i++){ echo "<br> Line to show."; echo str_pad('',4096)."\n"; ob_flush(); flush(); sleep(2); } echo "Done."; ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817448 Share on other sites More sharing options...
JonnoTheDev Posted April 23, 2009 Share Posted April 23, 2009 yes that works Quote Link to comment https://forums.phpfreaks.com/topic/155366-solved-db-question/#findComment-817456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.