Welcome Guest, Not a member yet? Register   Sign In
Gallery problem: one query, different images size
#1

[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 ?
#2

[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?)
#3

[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 ?
#4

[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.
#5

[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
)
#6

[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.




Theme © iAndrew 2016 - Forum software by © MyBB