So, I have some javascript code someone gave me that refreshes part of a page, and it works by refreshing a variable with a random number assigned to it. but when I try to refresh php code in it it will only run once. Why is this? Is there a way I can remedy this problem?
//other working php code
if(isset($_POST['hostgame']))
{
//do some stuff
print"<div id='target'> </div>";
}
<script >
setInterval(function refresh(){
// why isn't this refreshing? math.random is?
<?php
$query = "select * from gameStatus".$_SESSION['gamenumber'];
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_row($result))
{
list($id, $status) = $row;
}
$gameStatus=$status;
?>
var value = "<?php echo $gameStatus; ?>"+Math.round(Math.random()*100);
$('#target').addClass('hidden');
$('#target').html(value);
$('#target').removeClass('hidden');} , 1500);
</script>
</body>
</html>
so the gamestatus gets printed out the first time but doesn't get refreshed to show its latest changes in mysql. I checked the database and it is being changed, but not showed on screen. the random number is refreshing though. Can someone explain why? maybe how to fix it?