Welcome Guest, Not a member yet? Register   Sign In
Calculate the range of items shown on each page using codeigniter pagination
#2

[eluser]Harold Villacorte[/eluser]
I have no way to test this and I do not know what your queries look like but you might be looking to do something like this:
Code:
<?php
class Home extends CI_Controller {

function __construct()
{
    parent::__construct();
    $this->load->library("pagination");
}

public function index($page = NULL)
{
    $this->load->model('status_model');//load the status model
    // Set the per page.
    $per_page = 1;
    // Set the total count.
    $total_count = $this->status_model->count_active_entries();
    // Set the offset.
    $offset = ($page) ? $page : 0 ;    

    //pagination config
    $config = array();
    $config["base_url"] = site_url() . "/home/index";
    $config["total_rows"] = $total_count;
    $config["per_page"] = $per_page;
    //$config["uri_segment"] = 3;  This is not necessary.
    $config["anchor_class"] = 'class="normal" ';
    $config['full_tag_open'] = '<ul>';
    $config['full_tag_close'] = '</ul>';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['next_link'] = 'Next';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['prev_link'] = 'Prev';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="num_active">';
    $config['cur_tag_close'] = '</li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';

    $this->pagination->initialize($config);

    // Skip all this.
    //$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    //call the method to get all the active statuses
    $statuses = $this->status_model->get_entries($per_page, $offset);
    
    if($statuses !== false) {

        $content_data['results'] = $statuses;
    }
    else { // If no results are returned display the following error message

        $content_data['error'] = 'Error no status updates are being returned from the database. Please contact an administrator.';
    }

    // This normally works for me.
    $first_record = $offset + 1;
    $last_record = $page + count($statuses);
    echo "Showing " . $first_record . " to " . $last_record . " item of " . $total_count;

    $content_data["links"] = $this->pagination->create_links();
    $data['title'] = ' Status';                           //Browser page title
    $data['page_title'] = 'The Latest Status Updates';//The page H1 tag
    $data['content'] = $this->load->view('results', $content_data, TRUE);//the page content

    $this->load->view('home', $data);
    }
}


Messages In This Thread
Calculate the range of items shown on each page using codeigniter pagination - by El Forum - 01-29-2013, 10:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB