Welcome Guest, Not a member yet? Register   Sign In
Show album data and images in my view
#1

[eluser]Lykos22[/eluser]
Hi, I 'd like some help please. I have 2 tables:
Code:
Albums with:
album_id
title
description

and Albumimages with:
img_id
album_id
image_file

What I want to do is to fetch all data from these two tables , loop through them and display them in my view so it should look something like portfolio section (2nd screenshot) of this template as the ending result.

This is what I have so far in my controller:
Code:
// fetch all album data
$albums = $this->album_model->get();

// fetch all images of each album
foreach ($albums as $album ) {
$images = $this->albumimage_model->get_by('album_id', $album->album_id);
}

$data = array(
'albums'  =>  $albums,
'images'  =>  $images,
);
$this->load->view('album_listing', $data);

my view:
Code:
<?php foreach($albums as $album): ?>
<div class="left-col">
<p>&lt;?php echo $album->title; ?&gt;</p>
<p>&lt;?php echo $album->description; ?&gt;</p>
<div>
&lt;?php endforeach; ?&gt;

&lt;?php foreach($images as $image): ?&gt;
<div class="right-col">
<img src="uploads/&lt;php? echo $album-&gt;title;  ?&gt;.'/'.&lt;php? echo $image-&gt;image_file;  ?&gt; " />
</div>
&lt;?php endforeach; ?&gt;

I'm not sure if this is the best way to do it as the running queries (which shown in Profiler) will be increase when more albums added. Is there a better way to do this ??

NOTE: the ending result in my view should be like the 2nd screenshot you see on the link.


Messages In This Thread
Show album data and images in my view - by El Forum - 12-19-2013, 06:50 AM
Show album data and images in my view - by El Forum - 12-19-2013, 10:48 AM
Show album data and images in my view - by El Forum - 12-19-2013, 10:53 AM
Show album data and images in my view - by El Forum - 12-20-2013, 12:58 AM
Show album data and images in my view - by El Forum - 12-20-2013, 03:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB