PHP的回声第一行等待/睡眠,然后回声第二行 [英] php echo first row wait/sleep then echo second row

查看:75
本文介绍了PHP的回声第一行等待/睡眠,然后回声第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以从数据库的等待/睡眠表中回显第一行5秒钟,然后回显第二行?

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?

预先感谢您的帮助!

$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???
       }
   }
}

推荐答案

尝试使用输出缓冲.例如:

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);
           }
       }

这篇关于PHP的回声第一行等待/睡眠,然后回声第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆