I have built up a script to first query table 'linkags' in database for id's where 'id' is equal to 'userId' and 'type' is equal to 'type'.
I then use the result to query table 'linktagRevisions' to fetch the latest revision for the returned array of id's pertaining to that user.
I then output the list of 'linktagRevisions' in to a json output.
My issue has been that I have been unable to unserialize 'content'. So in building my array to output in json I have coded:
$data = array('linktag' => unserialize($result[$linkI]['content']));
Which successfully returns an unserialzed result, but it limits to one row even with the foreach loop in place. How can I use the loop to fetch all rows?
Here is my full code:
public function testAction()
{
//Return list of tags for the defined user and make default type 10
$u = 2;
$t = 10;
$resultid = array();
//Connect to database
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()
->from(array('lt' => 'Linktags'),
array('id'))
->where('userId = ?', $u)
->where('type = ?', $t);
$stmt = $select->query();
$resultid = $stmt->fetchAll();
//print_r($resultid);
//Get latest revision from database and loop through $id's
$id = $resultid;
//print_r($id);
//setup array and loop
$result = array();
foreach($id as $lId_all) {
foreach($lId_all as $lId) {
//Connect to database
$db = Zend_Db_Table::getDefaultAdapter();
//Perform Query
$select = $db->select('')
->from(array('lr' => 'LinktagRevisions'),
array('content'))
->where('linktagId = ?', $lId)
->order('updated DESC')
->limit(1);
$stmt = $select->query();
$result[$lId] = $stmt->fetch();
}
}
$linkId = $resultid;
foreach ($linkId as $linkI_all) {
foreach ($linkI_all as $linkI) {
//print_r($linkI);
$data = array('linktag' => unserialize($result[$linkI]['content']));
}
print_r($data);
$this->_helper->json($data, true);
}
}