CodeIgniter Forums

Full Version: Returning a nested resultset
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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:

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.

El Forum

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.