2

I've searched and can't find an answer to my question.

I have the following code which is to loop through an array and then fetch back results for the different $id's.
The output when using echo json_encode($row); returns all results but the zend layout displays.
However when using $this->_helper->json($row,true); the layout doesn't display but only one result returns.

How can I return more than one result?

Any help would be much appreciated.

public function testAction()

{



    //Get latest revision from database and loop through $id's
    $id = array('308', '307', '306');

    //Connect to database

    foreach($id as $lId) {

        $db = Zend_Db_Table::getDefaultAdapter();


        $select = $db->select('')
            ->from('LinktagRevisions')
            ->where('linktagId = ?', $lId)
            ->order('updated DESC')
            ->limit(1);

        $stmt = $select->query();
        while ($row = $stmt->fetch()) {


            $this->_helper->json($row,true);
    //Encode as json and echo result
           // echo json_encode($row);
        }


    }

}

1 Answer 1

1

I think you can try this:

$result = array();
foreach($id as $lId) {
    ....
    $stmt = $select->query();
    $result[$lId] = $stmt->fetchAll();

}
$this->_helper->json($result,true);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but that still only seems to return one result.
Sorry, I forget the 1rst loop. I update the answer. And I add Id index
You're welcome! Thank's for your return. :) Good Luck.

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.