-3

I currently use this code to reload the PHP content in a DIV every 5 seconds. $clan_ is a variable set to load a specific PHP page in to the div, its a variable as the data comes from whatever the user selects on the page.

what I want to be able to do is change the value in the variable $clan_ based on an array from PHP so the div updates with different content every time the interval runs. I'm getting stuck at how to loop though the PHP each time the interval runs.

<script>
$(document).ready(function(){
    $("#stats").load("<? echo $clan_ ;?>");
        setInterval(function(){
            $("#stats").load("<? echo $clan_ ;?>");
        }, 5000);
    });

</script>
Rob Craft
  • 1
  • 4

1 Answers1

1

That's not possible the way PHP works. PHP is processed on the server and doesn't "life reload" your website.

The code ecapsulated in is processed once before transmitting the response. If you want to update this you need to use XMLHttpRequest to be able to rerun the operation on the server and get an updated result.

E.G. https://www.w3schools.com/php/php_ajax_php.asp

There are many other examples. If you have any more problems, feel free to reach out.

msphn
  • 307
  • 2
  • 9
  • Sorry I wasn't clear, the array in PHP is created before it gets to this page so the array is already available. I just need to be able to loop that array in the interval code. – Rob Craft Jan 14 '19 at 22:20
  • My answer is still valid. setInterval is only operating on the DOM and doesn't do any requests which. Please check this post. The setInterval operation is pure client side! https://techdifferences.com/difference-between-server-side-scripting-and-client-side-scripting.html – msphn Jan 14 '19 at 22:46