0

how to convert zend_db_table_rowset object to javascript array

$db=new Application_Model_DbTable_Books();
        $result=$db->showBooks();

showBooks:

class Application_Model_DbTable_Books extends Zend_Db_Table_Abstract
{

    protected $_name = 'books';
    protected $_primary = 'id';
    public function showBooks(){
            return $this->fetchAll();


}

} I want to convert the result set in to something liket this:

  var aDataSet = [
                ['Trident','Internet Explorer 4.0','Win 95+','4','X'],
                ['Trident','Internet Explorer 5.0','Win 95+','5','C'],
                ['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
                ['Trident','Internet Explorer 6','Win 98+','6','A']];
1
  • Where's the catch? Just foreach over the rowset, no? Commented Aug 9, 2012 at 7:43

1 Answer 1

1

JSON fits bettew for such operations

Inside controller

$db=new Application_Model_DbTable_Books();
$result=$db->showBooks();    
$this->view->booksJson = Zend_Json::encode($result);

Inside view script

var aDataSet = JSON.parse(<?php echo $this->booksJson;?>);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.