Welcome Guest, Not a member yet? Register   Sign In
I'm rusty and need some help with an Active Record Query.
#1

[eluser]Ichabodcole[/eluser]
I'm a designer and have not coded anything in quite a while so please forgive me for what is probably an easy answer question, but I would greatly appreciate the kickstart!.

I currently have two related tables "Stacks" and "Chunks", and each "Stack" is made up of one or more "Chunks". The "Chunks" table has a foreign key called "stack_id" that relates to the "id" field in the "Stacks" table. I'm trying to create a DB query with the Active Record class that will give me something that I can loop over like the following code which would be in the view.

In the controller:
Code:
$data['stacks'] = $this->my_model->get_stacks_with_chunks();
$this->load->view('my_view', $data);

In the view:
Code:
foreach ($stacks as $stack)
{
   $stack_id = $stack->id
   $chunks = $stack->chunks;
   foreach ($chunks as $chunk)
   {
       $chunk_id = $chunk->id;
   }
}

So my question is what would my Active Record query look like in my model to get something like the above out of it? Guessing this is pretty simple, it's just been awhile since ive coded anything and I would probably create it in a very unoptimized way if i do it myself. Can this be down with only one DB call, using a Join or something?

Any help GREATLY appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB