Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
How do I create a pause in the execution of the code

I am wanting to create a list that reveals itself slowly on the screen, but it seems that all routines are completed before they present themselves.

For example:

for ($x = 0; $x <= 25; $x++)
{
 echo "The number is: $x <br>";
 sleep(1);
}

In my mind this should display "The number is 1", wait 1 second then display "The number is 2". In reality is waits 25 seconds and shows all the numbers, except there seems to be an error there too as it only actually displays the first 10 !!!

EDIT: I also tried "usleep" which had the same effect

I'm not concerned with the error, but how do I add some waiting please?

EDIT: Following on, I am still getting the same issue with this code.

 for ($x = 1; $x < 5; $x++)
 {
  $st=$_SESSION['st']=$x;
  echo '<iframe class="findlist" name="iframefindlist" id="findlist" src="findmelist.php"></iframe>';
  ob_flush();
  flush();
  usleep(3000000);
 }

And then the "findmelist.php" is

<body>
<?php
$st=$_SESSION['st'];
$conn = new mysqli("localhost", "acc", "pw", "db");

?>
<div class="findlist1">
</div>

<div class="findlist2">
 <?php

 $result = mysqli_query($conn,"SELECT * FROM tablename WHERE number='$st'");
 while($row = mysqli_fetch_array($result))
 {
  $fname=$row['fname'];
  $lname=$row['lname'];
 }
 echo $fname.' '.$lname;
 ?>
</div>

<div class="findlist3">
</div>

</body>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to flush the output_buffer first, otherwise the answer is only sent when the execution has finished.

ob_flush();
flush();

So for your code, that means:

for ($x = 0; $x <= 25; $x++)
{
 echo "The number is: $x <br>";
 ob_flush();
 flush();
 sleep(1);
}

For more info, see the following reference.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda