duandi8544 2017-02-08 15:22
浏览 462
已采纳

每秒执行一次while循环

I got this while loop that is displaying as you can see a username and a message which the user types... But after the message has been typed the user have to reload my page to see it. Is there a way to make the while loop execute while im on the site to keep it constantly updated?! like setting it to execute every second or something?

        <?php 
include "connect.php";
$query = "SELECT * FROM messages";
$result = $con->query($query);

if($result){

            while($row = $result->fetch_object()) 
            {
                echo "<ul id = 'rutor'>";
                echo '<li class = "userlada">'.$row->username. "</li>";
                echo '<li class = "usertext">'.$row->message. "</li>";
                echo "</ul>";
            }

}
?>

I'm not the brigetest on php so any help would be great!:)

  • 写回答

2条回答 默认 最新

  • drdu53813 2017-02-08 15:40
    关注

    No.

    PHP is server-side, so if you start waiting and looping there, you'll just make the browser wait for it to be done.

    For this you need to look into Javascript.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记