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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划