<script> var set_delay = 5000, callout = function () { $.ajax({ url: "get_data.php", }) .done(function (response) { $("#change_this_div").html(result); }) .always(function () { setTimeout(callout, set_delay); }); }; // initial call callout(); </script>
Now, the get_data PHP file looks like that:
<?php require_once 'connect.php'; $sql = "SELECT firstname FROM users WHERE id = :id"; $stmt = $conn->prepare($sql); $param_id = //some_id here $stmt->bindParam(':id', $param_id, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); ?>
How do I return the $result, which is the user's first name and display it in the div that I want to change? I can't find out
thanks!