Welcome Guest, Not a member yet? Register   Sign In
Using pagination
#6

(This post was last modified: 03-13-2018, 01:14 PM by jreklund.)

That's correct. You can fecth some things automatic, but some you need to pass along in the $data array.

You need to change your model to accept an offset. It dosen't know you want 20 iterations.

In case you get stuck and want to cheat.
PHP Code:
// Controller
public function page() {
    
$this->load->library('pagination');
    
$config['base_url'] = base_url('admin/ads/page');
    
$config['total_rows'] = $this->db->count_all('ads');
    
$config['per_page'] = 50;
    
$config['uri_segment'] = 4// You may need to change this into 3
    
$this->pagination->initialize($config);
    
    
// You need to change segment(4,1) so it's matching the same number as uri_segment, in your case 3
    
$offset = (intval($this->uri->segment(4,1))*$config['per_page'])-$config['per_page'];
    
    
$this->data['ads'] = $this->ads_model->get_all_ads($config['per_page'],$offset);
    
$this->load->view('admin/ads/list',$this->data);
}

// Model
public function get_all_ads($limit,$offset) {
    
$this->db->order_by('company''ASC');
    
$query $this->db->get('ads',$limit,$offset);
    return 
$query->result();
}

// application/config/pagination.php - Default setttings
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<nav aria-label="Page navigation"><ul class="pagination">';
$config['full_tag_close'] = '</ul></nav>';
$config['prev_link'] = 'Prev.';
$config['next_link'] = 'Next';
$config['first_link'] = FALSE;
$config['last_link'] = FALSE;

$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';

$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';

$config['cur_tag_open'] = '<li><span>';
$config['cur_tag_close'] = '</span></li>';

$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['num_links'] = 4
Reply


Messages In This Thread
Using pagination - by barrypoore - 03-12-2018, 01:36 PM
RE: Using pagination - by jreklund - 03-13-2018, 01:32 AM
RE: Using pagination - by barrypoore - 03-13-2018, 11:12 AM
RE: Using pagination - by jreklund - 03-13-2018, 11:33 AM
RE: Using pagination - by barrypoore - 03-13-2018, 11:47 AM
RE: Using pagination - by jreklund - 03-13-2018, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB