victorianrider Posted November 12, 2010 Share Posted November 12, 2010 Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. Quote Link to comment Share on other sites More sharing options...
simshaun Posted November 12, 2010 Share Posted November 12, 2010 I don't think it possible without refreshing the page (which you probably don't want). Once data is sent to the browser from the script, its up to the browser to do something with it (meaning its out of PHP's hands). I've got an idea, but I don't think its very efficient and may not work as intended due to several factors affecting 'flush()'. Have your script echo '<div>content here</div>' and flush() it to the browser, and setup an interval in js to remove "old" div elements from a container. Quote Link to comment Share on other sites More sharing options...
victorianrider Posted November 12, 2010 Author Share Posted November 12, 2010 I don't think it possible without refreshing the page (which you probably don't want). Once data is sent to the browser from the script, its up to the browser to do something with it (meaning its out of PHP's hands). I've got an idea, but I don't think its very efficient and may not work as intended due to several factors affecting 'flush()'. Have your script echo '<div>content here</div>' and flush() it to the browser, and setup an interval in js to remove "old" div elements from a container. Thanks I'll try something like that. Cheers mate Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2010 Share Posted November 13, 2010 The only way to do this is to use Javascript to control the loop and make AJAX calls back to your PHP script within the loop. You would then use Javascript to update the window. I would use the jQuery library for this. Quote Link to comment 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.