Slowly recount the number of records in a table

Asked

Viewed 41 times

1

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

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

I’m waiting for help!

  • That is, you want the user of your site to see the client counter being incremented: "Registered customers: 0", "Registered customers: 1", [...] "Registered customers: TOTAL"? type, the counter is incremented by 1 every X seconds?

  • @tayllan that’s right! Correct

  • Maybe you wanted to take a look at Easing Functions, is the same principle of Fade-In and Fade-Out functions that you want to do, but in the case, instead of affecting the opacity of an image, you want it to be Total Clients multiplied by the function value. http://easings.net/pt

  • You have a functional demonstration right here at Sopt: http://answall.com/questions/102170/como-usar-unidade-de-tempo-menor-que-milissegundos-em-um-setinterval-ou-settimeo/102175#102175

2 answers

2

Use the function setInterval() javascript:

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> 1 every 500 milliseconds. You can change the increment interval however you want, make it faster or slower.

TOTAL_CLIENTES is your value coming from PHP:

var TOTAL_CLIENTES = <?php echo $admcadastros; ?>;

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 operation here:

php calls by ajax

Browser other questions tagged

You are not signed in. Login or sign up in order to post.