当用户收到新消息时,重新加载页面。
我正在开发一个PHP聊天应用程序。管理员和用户可以聊天的地方。
当出现新消息时,用户需要重新加载页面并从数据库中获取新消息。
我的查询是: -
$query = "SELECT * FROM `chat`
WHERE fromthe = '$email' and tothe='theadmin'
UNION ALL SELECT * FROM `chat`
WHERE fromthe = 'theadmin' and tothe='$email' order by id desc";
$sql1 = "UPDATE `chat` SET `status`='1' where tothe='$email'";
mysqli_query($con, $sql1);
请帮我做。
由于
答案 0 :(得分:0)
您可以使用setInterval
并每隔x秒点击一次数据库以检查新消息是非常糟糕的做法,还是使用websocket