如何创建基于数据库条目不断更新的进度条[关闭]

OK so I have MySQL database locally hosted using XAMPP. I am trying to code a progress bar that will be updated based on the count returned from a database table. This will act as showing the capacity of a location. So if there are X amount of entries in the database the table then the progress bar will show as X full. And it will get updated as the page is refreshed. I have my database connected but am unaware of the logistics of doing this with a progress bar or if it is possible. Any better solutions I am open to. Thanks in advance.

You can achieve this in PHP with Long Polling.

Create a small PHP file that exists solely to respond to ajax requests with the entry count of the database.

entrycount.php

<?php
    session_start();
    if (!$_SESSION['LOGGED_IN'])
        exit();
    // get entry count from database
    exit($entry_count);
?>

And poll this value on a loop using chained timeouts (until the progress bar is full or some other condition is met).

HTML

function updateProgressBar()
{
    var request = new XMLHttpRequest();
    request.open("get", "entrycount.php", true);
    request.onreadystatechange = function()
    {
        if (request.readyState == 4 and request.status == 200)
        {
            var entryCount = request.responseText;
            // update progress bar with new count
            if (keepPolling)
                setTimeout(updateProgressBar, 5000);
        }
    }
    request.send();
}
setTimeout(updateProgressBar, 5000);