0

I am trying to refresh SQL data that is displayed onto my page. I want it to refresh every second. At the moment, after the balance has been displayed, after the 1 second the data stays but it doesn't update.

JS Code:

<script>
$(document).ready(
        function() {
            setInterval(function() {
                var htmlstring= "<?php echo "Balance: $".$_SESSION['Money']." || "; ?>";
                $('#money').text(htmlstring);
            }, 1000);
        });
</script>

HTML+PHP code:

<span id="money"><?php echo "Balance: $".$_SESSION['Money']." || ";?></span>

This is where the session is being set:

session_start();
$con = mysqli_connect("localhost", "root", "", "website");
if (isset($_SESSION['UserID'])) {
$result = $con->query("select * from users where   UserID=".$_SESSION['UserID']);
$row = $result->fetch_assoc();
    $_SESSION['Money'] = $row['Money'];

Could it be because the session that is set isn't being refreshed? If so, how would I change that?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Lewis Hoggerson
  • 37
  • 2
  • 12

0 Answers0