I'm making a basic chat room. My code:
$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>");
}
Every time you refresh the page, this updates, and any records that have been added since the last refresh are added to the list. In a chat room, this isn't ideal, so is there a way to have this constantly checking for new records with as little disruption to the user as possible? Thanks!