Send two dimensional array to javascript


in controller i want query database and send 2 dimensional array data to view and traverse it every 2 second with javascript! when i send data like below command

$this->render("index", array('2dimentionalArray'=>$data));

I can’t traverse it every 2 seconds!

How can i traverse this array with javascript every 2seconds and show it’s data?

Is json solution of my problem?If yes please show me an example.


//  in  your view file :

<script type="javascript/text">

var myJsArray = <?php echo CJSON::encode($2dimentionalArray); ?>; // but why it's starts witch "2"

//here use myJsArray as  a normal js  variable . js timer is ok 


and additional i think you want use ajax to query the 2dimentionalArray every 2 seconds ?

   //js side 

   function repeatRequest(){

    var   url = "<?php  echo  $this->createUrl('someActionId'); ?>";


        // handle the response here !

        here use js timer to repeat this function again !(2 seconds latter )



  repeatRequest(); // start it 

  // server side :

  public function someAction(){

    // query db

    echo CJavaScript::encode($resultSetFromDb);



  // you may need to put this action to accessRules or check if it is ajax request

Thanks for your reply and help

I query the database in my php code and save it in 2dimensional array and send this array to view file.In view file i get data from this 2dimesional array with setTimeout function of java script to get vehicle location every 2 seconds and create route of vehicle.

Is this approach true?I don’t want to query database every 2 seconds and send request to server!.Is this approach true for speed up application?