0

So I'm using a free web hosting service to test my code out (which is a public messaging board) and when a message is sent to the database table from another computer, where every message is stored, the message can't be seen until I refresh the page. Is there a way to automatically refresh the table when the database table changes?

Here's the code I'm using to display the database table:

<?php
        include_once "includes/database.php";
        $sql = "SELECT * FROM board ORDER BY id DESC";
        $result = mysqli_query($conn, $sql);
        $resultCheck = mysqli_num_rows($result);
        if ($resultCheck > 0) {
            while ($row = mysqli_fetch_array($result)) {
                echo "<tr>";
                echo "<td>" . ($row['timstmp']) . "</td>";
                echo "<td>" . ($row['user_id']) . "</td>";
                echo "<td>" . ($row['message']) . "</td>";
                echo "</tr>";
            }
        }
    ?>

here's a photo of the database table and here's a photo of the website.

I've tried automatically refreshing the page itself on a timer but that clears text fields that could be in use.

794677
  • 1
  • PHP is server-side and your browser is client-side. In *theory* this would be possible, but the only ways I can think of doing it would be to a) use AJAX (from JavaScript) to poll a PHP page that returns a certain `response` when the processing is done, or b) to use a PHP socket implementation of something like SignalR. I believe Ratchet might work in this regard. – Obsidian Age Jan 29 '20 at 21:57
  • Add a hint: websocket – Renato Jan 29 '20 at 22:00
  • https://www.xaprb.com/blog/2011/09/15/5-subtle-ways-youre-using-mysql-as-a-queue-and-why-itll-bite-you/ – spencer7593 Jan 29 '20 at 22:01
  • https://www.eschrade.com/page/why-mysql-is-not-a-queue/ – spencer7593 Jan 29 '20 at 22:01

0 Answers0