• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Join one to many

#2
[eluser]apodner[/eluser]
Here's a quick & dirty possibility (but the better solution is to set this all up as separate methods in a model):


Code:
$galleryQuery = $this->db->get('gallery');
foreach ($galleryQuery->result_array() as $key => $row) {
    $data[$key] = $row;
    $this->db->where('gallery_id', $row['id_gallery']);
    $imgQuery = $this->db->get('images');
    $data[$key]['images'] = $imgQuery->result_array();  
}
return $data;


View: ( I assume each gallery goes with one figure tag)

Code:
<?php
foreach($data as $gallery) { ?>
    <figure>
        &lt;?php
         foreach($gallery['image'] as $image) {
             /* code for whatever you do with each image in the figure */
         }
         ?&gt;
    </figure>

&lt;?php
}
?&gt;


Messages In This Thread
Join one to many - by El Forum - 11-27-2012, 01:10 PM
Join one to many - by El Forum - 11-27-2012, 09:15 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.