我想知道有没有办法在数据库等待/休眠状态下从表中回显第一行5秒然后回显第二行?
提前感谢您的帮助!
$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???
}
}
}
答案 0 :(得分:2)
尝试使用output buffering。例如:
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);
}
}
答案 1 :(得分:0)
您可以使用sleep()
功能:
echo '<div class="animatedText"> ';
while ($row = $strSql->fetch_assoc()) {
$rows[]=$row;
foreach($rows as $row){
$words1=$row['words'];
echo $words1;
sleep(5);
}
}
echo '</div>';