YSimeonov
YSimeonov

Reputation: 13

php echo first row wait/sleep then echo second row

I would like to know is there a way to echo first row from table in database wait/sleep for 5 seconds and then echo the second row?

Thank you in advance for your help!

$conn = mysqli_connect('localhost', 'root', '','database');
$strSql=$conn->query("SELECT words FROM load ORDER BY id ASC ");
if($strSql->num_rows >0) {
    while ($row = $strSql->fetch_assoc()) {
    $rows[]=$row;
    foreach($rows as $row){
       $words1=$row['words'];
               echo '<div class="animatedText"> '.$words1.'</div>';
       //let's say sleep(5); and then print second row???
       }
   }
}

Upvotes: 1

Views: 963

Answers (2)

Gogol
Gogol

Reputation: 3070

try using output buffering. For example:

header( 'Content-type: text/html; charset=utf-8' );

while ($row = $strSql->fetch_assoc()) {
      $rows[]=$row;
       foreach($rows as $row){
            $words1=$row['words'];
            echo '<div class="animatedText"> ';
            echo $words1;
            echo '</div>';
            flush();
            ob_flush();
            sleep(5);
           }
       }

Upvotes: 3

Gouda Elalfy
Gouda Elalfy

Reputation: 7023

you can use sleep() function:

echo '<div class="animatedText"> ';
while ($row = $strSql->fetch_assoc()) {

      $rows[]=$row;

       foreach($rows as $row){
           $words1=$row['words'];

           echo $words1;
           sleep(5);

           }

       }
echo '</div>';

read more

Upvotes: 1

Related Questions