I'm not sure how efficient this code is, but you can use the combination of group_concat and concat of the mysql function to get the data in a single row / column from a subquery, then you can reload it back into an array in PHP.
select id, title, group_concat(concat(b.ID, '@@', b.link)) as linkies from article a right outer join links b on b.article_id=a.ID group by id, title
This will cause this to return to the PDO results:
ID | Title | linkies 1 | bla bla | 1@ @yourLink, 2@ @SomeOtherLink 2 | ble ble | 1@ @yourLinkRow2, 2@ @SomeOtherLinkAgain
Once in PHP it would be easy to return to arrays.
source share