Slowly count the number of records in a table

1

Hello everyone, I have a field on my site that displays the number of registered customer records. How to retell this record more slowly for the user to view this recount?

Example: Clientes cadastrados: <?php echo $admcadastros; ?>

I look forward to helping you!

    
asked by anonymous 07.03.2016 / 17:15

2 answers

2

Use the JavaScript setInterval () :

var contador = document.getElementById('contador');
var TOTAL_CLIENTES = 10;

var intervalo = setInterval(function() {
  contador.innerHTML = parseInt(contador.innerHTML, 10) + 1;

  if (contador.innerHTML == TOTAL_CLIENTES) {
    clearInterval(intervalo);
  }
}, 500);
<p>Clientes cadastrados: <span id="contador">0</span></p>

The above code will increment the value of <span> by 1 every 500 milliseconds. You can change the increment interval as you want, leave it faster or slower.

TOTAL_CLIENTES is your value from PHP:

var TOTAL_CLIENTES = <?php echo $admcadastros; ?>;
    
07.03.2016 / 18:16
0

You can use a meta tag to refresh your page from time to time:

<meta http-equiv="refresh" content="5"> // 5 segundos

Or by AJAX, explained its working here:

#

    
07.03.2016 / 18:02