Welcome Guest, Not a member yet? Register   Sign In
Join one to many
#1

[eluser]Unknown[/eluser]
I have to tables:

gallery -> id_gallery, name, desc, data

and:

images -> gallery_id, name,path

One gallery can have many images. I need to select all galleries and all images and on view page present all galleries and all images which contains that gallery. How can do this?

I have code like this for now:

Code:
$q = $this->db->select('*')->from('gallery')->join('images','images.gallery_id = gallery.id_gallery')->get();
  return $q = $q->result_array();

And foreach loop in view:

Code:
<?php foreach ($gallery as $gal):  ?>
    <figure>
    <a href="&lt;?php echo IMG ?&gt;galerija/&lt;?php echo $gal['name'] ?&gt;/&lt;?php echo $gal['path'] ?&gt;" rel="galerija[slike]" class="figure_img">
    <img src="&lt;?php echo IMG ?&gt;galerija/&lt;?php echo $gal['naziv'] ?&gt;/thumbs/&lt;?php echo $gal['path'] ?&gt;" >
    <figcaption>&lt;?php echo $gal['name']; ?&gt;</figcaption>
    </a>
    </figure>
    &lt;?php endforeach; ?&gt;

This foreach loop is producing 5 figure tags instead of one (if gallery have 5 images for example). I need to create one figure tag, and inside it I need to create a tag for every image in that gallery. How can I do this?


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



Theme © iAndrew 2016 - Forum software by © MyBB