• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination Help

#1
Hi All,

I'm running into an issue with Pagination. Not used CI in years so a little rusty.

The issue is when I click on a page it does not load the data for that page and keeps it as the first record but the page number changes.
What noob mistake have I done?

Controller - Site.php
PHP Code:
    public function view($offset 0)
    {
        
$this->output->enable_profiler(TRUE);
        
$this->load->model('View_Model');
        
        
$limit 1;
        
$result $this->View_Model->get_images($this->uri->segment(2),$limit$offset);
        
$count $this->View_Model->count_images($this->uri->segment(2));
        
$data['images'] = $result['rows'];
        
        
$config = array();
        
$config['base_url'] = base_url() . "view/".$this->uri->segment(2)."";
        
$config['total_rows'] = $count['num_rows'];
        
$config['per_page'] = $limit;
        
$config['uri_segment'] = 3;
        
$config['use_page_numbers'] = TRUE;
        
$config['cur_tag_open'] = '&nbsp;<a class="current">';
        
$config['cur_tag_close'] = '</a>';
        
$config['next_link'] = 'Next';
        
$config['prev_link'] = 'Previous';
        
        
$this->pagination->initialize($config);
        
        
$data['pagination'] = $this->pagination->create_links();
        
        if (
$this->uri->segment(2) == TRUE)
        {
            
//Select Album Info
            
$get_album_slug $this->db->get_where('albums', array(
                
'album_slug' => $this->uri->segment(2)
            ));
            
            
//Check to see if an album record is found and fail if not
            
if ($get_album_slug->num_rows() <= 0) {
                echo
"Nothing Found";
            }
            
            
// Load Template Output
            
$data['main_content'] = 'view';
            
$this->load->view('template'$data);
        }
        else
        {
         
       Echo"Failed Seg 3";
        }
    } 

Model - View_Model.php
PHP Code:
       public function __construct()
 
       {
 
               // Call the CI_Model constructor
 
               parent::__construct();
 
       }

 
       public function get_images($album_slug$limit$offset)
 
       {
                if (
$offset 0) {
                    
$offset = ($offset 1) * $limit;
                }
                
//Get Images assigned to the Album
                
$this->db->select('*');
                
$this->db->from('albums');
                
$this->db->where('album_slug'$album_slug); 
                
$this->db->join('images''albums.album_id = images.album_id');
                
$this->db->limit($limit,$offset);
                
$result['rows'] = $this->db->get();
                return 
$result;
 
       }
        
        public function 
count_images($album_slug)
 
       {
                
//Get Images assigned to the Album
                
$this->db->select('*');
                
$this->db->from('albums');
                
$this->db->where('album_slug'$album_slug); 
                
$this->db->join('images''albums.album_id = images.album_id');
                
$result['num_rows'] = $this->db->count_all_results();
                return 
$result;
 
       

Routes.php
PHP Code:
$route['view/(:any)'] = 'site/view/(:any)';
$route['view/(:any)/(:num)'] = 'site/view/(:any)/$1';
$route['view'] = 'site/view'
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.