CodeIgniter Forums
Returning a nested resultset - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Returning a nested resultset (/thread-38573.html)



Returning a nested resultset - El Forum - 02-11-2011

[eluser]Unknown[/eluser]
Hi guys,

My scenario is the following:
- I have news items, which can have many assets. News are stored in the "content" table and their assets are linked back from the "assets" table.

I'd like to create a list_all function that returns all the news items with their associated assets, so that I can loop through and display a news listing in my view.

I'm not quite sure how to achieve this. In my view it would be something like:

Code:
foreach news as item
   echo news->date_created
   echo news->title
   foreach news->assets as asset
      echo asset->title
   end foreach
end foreach

Currently I've got a list of all news, but not an asset association. Would appreciate some pointers.


Returning a nested resultset - El Forum - 02-11-2011

[eluser]Unknown[/eluser]
Got it, I used array notation. I was hoping to be able to do it with object notation but I'm not sure that I can.