Welcome Guest, Not a member yet? Register   Sign In
Paginating through invidual records
#1

[eluser]eokorie[/eluser]
I am trying to setup a photo gallery with CI. I have a page that display the main image. Is it possible to use the pagination class to navigate through individual records?
#2

[eluser]tomcode[/eluser]
Yes, what is Your question ?
#3

[eluser]eokorie[/eluser]
Well I am actually trying to set the code up and so far, I am not having much luck. This is what I have so far. Not very sure if I an doing the right thing or doing things the right way.

code in model
Code:
function _display_photo($user, $album_id, $photo_id, $limit='', $offset='')
        {
            $user = trim($user);
            $this->db->select('*');

            $this->db->where('id_pho',$photo_id);
            $this->db->where('id_usr',$user);
            $this->db->where('id_alb',$album_id);
            $this->db->limit($limit);
            $query = $this->db->get('bp_photos');
            
            if ($query->num_rows() == 1)
              {
                return $query->row();
              } else {
                return false;
              }
              
              // return $user . " " . $album_id . " " . $photo_id;
        }

code in controller
Code:
function photo($user, $album_id, $photo_id, $limit='', $offset='')
    {
        if ($user)
        {
            
            $data                    = array();
            $template_skin             = "templates/bamboo";    
            
            $limit = 1;
            $total = $this->profile_model->get_total_photos($this->uri->segment(2), $this->uri->segment(3));
            $offset = $this->uri->segment(4);
            
            $config['base_url']         = base_url().'members/photos/'.$user.'/'.$album_id.'/'.$photo_id;
            $config['total_rows']         = $total;
            $config['per_page']         = $limit;
            $config['uri_segment']         = 4;
        
            $this->pagination->initialize($config);
            
            $data['page_links'] = $this->pagination->create_links();
            
            $data['site_name']         = "Beep CI";
            $data['page_title']     = "'s photo";
            $data['meta']             = array('description'     => 'welcome to codeigniter',
                                                'keywords'         => 'welcome, codeigniter, ci',
                                            );
            $data['photo']     = $this->profile_model->_display_photo($this->uri->segment(2), $this->uri->segment(3), $this->uri->segment(4), $limit, $offset);
            
            $data['content'] = $this->load->view('display_photo', $data , TRUE);
            $this->load->view($template_skin . '/template_inc', $data);
        } else {
            echo "This member does not exist";
        }


code in view file:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<h1>&lt;?php echo "TEST"; ?&gt;</h1>
&lt;?php echo anchor(base_url() .'members/photos/' . $this->uri->segment(2) . '/' . $this->uri->segment(3), '&laquo; Return to photos'); ?&gt;
<p>&nbsp;</p>
<p>[ Photo Navigation Links ]</p>
<p>&lt;?php echo $page_links; ?&gt;</p>
<div class="photo_details" style="width: 620px; margin: 0 auto">
<img style="display:block; position:relative; top:-3px; left:-3px; border:10px solid #ccc;">uri->segment(2) . '/' . $this->uri->segment(3) . '/' . $photo->filename_pho; ?&gt;" alt="photo_&lt;?php echo $photo->id_pho; ?&gt;"/>
<p>&nbsp;</p>
<p>[ Add Photo Details ]</p>
<p>[ Add Rating System ]</p>
<p>[ Add Photo Comment System ]</p>

</div>

When I view the page in he browser, it displays the links but not the way I am hoping they should. I just want to display Next and Previous buttons but at the moment, I am getting
First < 8 9 10.

Is there something I can do to sort this?

Thanks
#4

[eluser]tomcode[/eluser]
Well, I wouldn't use the Pagination class at all.

I would use, like the Pagination class, an URI segment with a numeric value to indicate the actual page.

Then I'd write a previous and next function returning the desired URI numbers (URI segment +- 1, what to do when max number reached, range check).

Then two links in the view and I am done.

Edit : I gave You the wrong answer in my first reply, the Pagination class is not suited for this task.
#5

[eluser]eokorie[/eluser]
No probs Tom,

I will write the needed functions. Thanks for your input.




Theme © iAndrew 2016 - Forum software by © MyBB