Suppose I have 2 divs. I have to populate them with first 2 elements of an array. Then auto refresh the divs and they should get auto populated by next 2 items of the array. This should repeat till the end of array. After each element is traversed, auto refresh should stop.
For example, I have 8 elements in my array and 2 divs (mydiv1 and mydiv2). I want that after every second, divs should refresh themselves. First time mydiv1 contains A1 and mydiv2 contains A2, second time mydiv1 = B1, mydiv2=B2....so on 4 times
My xyz.php file
<?php
//echo rand();
$questions=array(
"A1",
"A2",
"B1",
"B2",
"C1",
"C2",
"D1",
"D2"
);
?>
My index.php file
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var auto_refresh = setInterval(
function ()
{
$('#mydiv1').load('xyz.php').fadeIn("slow");
}, 1000); // refresh every 1000 milliseconds
});
</script>
</head>
<body>
<div id="mydiv1"> </div>
<div id="mydiv2"> </div>
</body>