I use this script to reload a DIV whose ID is news,
<script type="text/javascript">
var auto_refresh = setInterval(function() {
<? if ($lim >= 5)
$lim = 0;
else
$lim = $lim + 2;
if ($cnt == 1){
$lim = 0;
$cnt += 1;
} ?>
$('#news').load('update.php?lim=<? echo $lim ?>');
}, 10000); // refresh every 10000 milliseconds
</script>
The update.php containts this code to receive the value for lim,
$lim=$_GET['lim'];
But after every 10 seconds the ‘lim’ value is sent as 0. I need to update the ‘lim’ value based on the condition in the script.
I checked in update.php for $lim value using echo command. Always it is 0. What is the bug in my code?
You seem a little confused as to what is serverside/clientside.
$limis a PHP variable, so is only available on the server side. You need to change your logic over to be javascript. Try this:Alternatively you could change the logic to make an AJAX request on each iteration of the timer which passes the
limvariable to your PHP and receives back the new value.