我正在制作一个基本的聊天室。我的代码:
$conn = ("127.0.0.1","root","","mymessages");
$stmt = "SELECT * FROM posts ORDER BY timestamp LIMIT 100";
$result = mysqli_query($conn, $stmt);
if(!$result) {
echo("Query failed" . mysqli_error());
}
while ($row = mysqli_fetch_assoc($result)) {
$messagefname = $row['fname'];
$messagelname = $row['lname'];
$subject = $row['subject'];
$content = $row['content'];
$day = $row['day'];
$month = $row['month'];
$year = $row['year'];
$hour = $row['hour'];
$min = $row['minute'];
echo("<font size='1.5' face='Arial'>");
echo("Sent by " . $messagefname . " " . $messagelname . " at " . $hour . ":" . $min. " on " . $day . "/" . $month . "/" . $year . "<br>");
echo("</font><br><font size='4' face='Arial'><b>");
echo($subject);
echo("</font><br><font size='3' face='Arial'></b>");
echo($content);
echo("</font><br><br><hr><br>");
}
每次刷新页面时,此更新以及自上次刷新后添加的所有记录都会添加到列表中。在聊天室中,这并不理想,那么有没有办法让它不断检查新记录,同时尽可能少地对用户造成干扰?谢谢!
子衿沉夜
相关分类