Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda