CodeIgniter Forums
Gallery problem: one query, different images size - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Gallery problem: one query, different images size (/thread-3266.html)



Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Référencement Google[/eluser]
Hi,

I am stopped with a problem.
I have 1 DB query that return 5 rows, that rows are the photo files.
My gallery has 1 big picture and then 4 thumbnails. I don't know how to make that working, need some help. Some code will help:

In the model, the query:
Code:
SELECT * FROM nip_photo LIMIT 5

Then, in the controller:
Code:
// The function _get_latestProfiles() retrieve the photos data from the DB
$data['latestpics'] = $this->_get_latestProfiles();
$this->load->view('gallery', $data);

Then the view:
Code:
<!-- HERE is my problem,
I would like from the query to get the first row as the big picture,
then loop in the foreach to get the other thumbnails that must be different from
the big picture -->
<img class="big_picture" src="here I want the big picture" />

<div class="thumbnails">
&lt;?php foreach($latestpics as $pic): ?&gt;
    
    <img src="thumb-&lt;?=$pic->photo_file?&gt;" />

&lt;?php endforeach ?&gt;
</div>

Note that I simplified my original code.
I don't have problem printing thumnails on screen, this is working, I just don't know how to make things to get the first DB row as the big picture and the following result rows as thumbnails.

Some help ?


Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Michael Wales[/eluser]
Code:
$query = $this->db->get('nip_photo', 5, 0);
$i = 0;
foreach ($query->result() as $row) {
  $i++;
  $data['pics'][$i] = $row->filename;
}

// $data['pics'][1] will always be your first row (the large one?)
// $data['pics'][2] - $data['pics'][5] will be your other rows (thumbnails?)



Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Référencement Google[/eluser]
That's a very good start for me Walesmd, thank you.
Now, I've got difficulties with arrays, I am again stopped with thumbnails loop, so actually my code looks like that:

Code:
&lt;?php
        
        $i = 0;        
        foreach($latestprofiles as $profile)
        {
            $i++;
            $data['pics'][$i] = $profile->photo_file;            
        }
        
        // $data['pics'][1] will always be your the big picture
        // $data['pics'][2] -> $data['pics'][...] will be thumbnails
        
        // We reset $i to 2, then we will start below the thumbnails loop at 2
        $i = 2;
        
        ?&gt;
        
        <a class="big_picture" href="&lt;?=site_url('members/register')?&gt;" title="Voir le profil de Simonne"><img src="&lt;?=$GLOBALS['photos_path'].$data['pics'][1]?&gt;" /></a>
        
        <div class="thumbnails clearfix">
            
            &lt;!-- HERE I don't know how to make --&gt;
            &lt;?php foreach($data['pics'][$i] as $thumb_file): ?&gt;            
            
            <a href="&lt;?=site_url('members/register')?&gt;" title="Voir les actrices porno et acteurs porno"><img src="&lt;?=$GLOBALS['photos_path'].'thumbs/th_'.$thumb_file?&gt;" /></a>
            
            &lt;?php endforeach; ?&gt;

How should I do ?


Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Michael Wales[/eluser]
Code:
&lt;?php foreach($data['pics'] as $id => $image): ?&gt;
&lt;?= site_url('members/register')?&gt;" title="Voir les actrices porno et acteurs porno"><img src="&lt;?=$GLOBALS['photos_path'].'thumbs/th_'.$image?&gt;" /></a>
&lt;?php endforeach; ?&gt;

That should work for you.

If not, do a print_r of your array $data['pics'] and paste here for me.


Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Référencement Google[/eluser]
That works partially. I've got now the first thumbnail the same as the large picture, this is what I wanted to avoid, I need that the large picture is different that all the thumbnails.

I post the full actual code:
Code:
&lt;?php
        
        $i = 0;        
        foreach($latestprofiles as $profile)
        {
            $i++;
            $data['pics'][$i] = $profile->photo_file;            
        }
        
        // $data['pics'][1] will always be your the big picture
        // $data['pics'][2] -> $data['pics'][...] will be thumbnails
        
        ?&gt;
        
        <a class="big_picture" href="&lt;?=site_url('members/register')?&gt;"><img src="&lt;?=$GLOBALS['photos_path'].$data['pics'][1]?&gt;" /></a>
        
        <div class="thumbnails clearfix">
                        
            &lt;?php foreach($data['pics'] as $id => $thumb): ?&gt;          
            
            <a href="&lt;?=site_url('members/register')?&gt;"><img src="&lt;?=$GLOBALS['photos_path'].'thumbs/th_'.$thumb?&gt;" /></a>
            
            &lt;?php endforeach; ?&gt;

And the print_r of $data['pics']
Code:
Array
(
    [1] => file_01.jpg
    [2] => file_02.jpg
    [3] => file_03.jpg
    [4] => file_04.jpg
    [5] => file_05.jpg
)



Gallery problem: one query, different images size - El Forum - 09-20-2007

[eluser]Référencement Google[/eluser]
Just found it! This code does the trick:
Code:
&lt;?php for($i = 2; $i <= count($data['pics']); $i++): ?&gt;          
    <a href="&lt;?=site_url('members/register')?&gt;"><img src="&lt;?=$GLOBALS['photos_path'].'thumbs/th_'.$data['pics'][$i]?&gt;" /></a>            
&lt;?php endfor; ?&gt;

Thanks Michael, you put me on the way.