Currently I need to do some looping result of calculation for every 5 second. Is there any code in HTML, PHP or JavaScript where I can display updating result in single place, not creating in new line. Below is example of code I'm working on in PHP:
<?php
set_time_limit(0);
ob_implicit_flush(true);
ob_end_flush();
$total=0;
for ($i=1; $i<980; $i++) {
$total=$total+1;
echo "The current number is".$total;
echo '<br>';
sleep(5);
}
?>
setInterval(function(){phpJavascriptClock();},2000); function phpJavascriptClock() { var total=0; for (var i=1; i<980; i++) { total=total+1; } document.getElementById("time_update_val").innerHTML= total ; }
<span id="time_update_val" class="notranslate">1</span>
The "echo" part should be outside the "for" loop.
<?php
set_time_limit(0);
ob_implicit_flush(true);
ob_end_flush();
$total=0;
for ($i=1; $i<980; $i++) {
$total=$total+1;
sleep(5);
}
echo "The current number is".$total;
?>
use jquery
var loopCounter = 0; (function addCount() { setTimeout(function() { if (loopCounter++ < 949) { $('#result').html(loopCounter); addCount(); } }, 500); })();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p id='result'>start</p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.