-2

I want to get value of PHP array index after a specific time interval. for this i am doing this. Problem : I am getting only [0] index value of PHP array but i need next then next after a Interval. How could i do this ?

<?php $row = 0; ?>
    var refreshId = setInterval( function() {

                        console.log("<?php echo $Array[$row]['created_at']; ?>");

                        <?php $row++; ?>    
                    }, 2000);

Sample Array:

Array
(
    [0] => Array
        (
            [created_at] => 19 Sep
        )
    [1] => Array
        (
            [created_at] => 20 Sep
        )
    [2] => Array
        (
            [created_at] => 21 Sep
        )   
)
Naresh
  • 2,761
  • 10
  • 45
  • 78
  • possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Whymarrh Sep 22 '14 at 10:38
  • it is not duplicate question – Sudharsan S Sep 22 '14 at 10:41

2 Answers2

1

You ARE incrementing the php variable, but the problem is you only increment once because its not in a loop.

You probably need a loop like this:

<?php 
$count = count($sampleArray);
for ($row = 0;$row<$count;$row++){ //start loop ?>
var refreshId = setInterval( function() {

                    console.log("<?php echo $Array[$row]['created_at']; ?>");


                }, 2000);

<?php }  // endloop ?>
andrew
  • 9,313
  • 7
  • 30
  • 61
  • 1
    Its too bad you got down voted, be careful when asking questions with javascript and php knitted together, as people who don't read properly may think you're trying to continue to execute the php after the output has been delivered to the browser – andrew Sep 22 '14 at 11:00
0

You must print the variable row

<?php $row = 0; ?>
    var refreshId = setInterval( function() {
                        console.log("-------------------------------------");
                        console.log("<?php echo $Array[$row]['created_at']; ?>");
                        console.log("<?php echo $Array[$row]['created_at']; ?>");
                        console.log("<?php echo $Array[$row]['created_at']; ?>");
                        console.log("-------------------------------------");
                        <?php $row++; 

                        echo $row; 

                         ?>    
                    }, 2000);
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49