0
votes

Hey, guys. I have a problem with pagination in my Codeigniter project. I am using the pagination library, and I have a search form. When I search for something, the results display on the page. When the resulting rows are more than the limit, I show the pagination links. But when I click on link number 2 to go to second page, the pagination links disappear. My search code is given below...

Controller function:

function search_branch()
{
                   $this->load->library('pagination');
        $search_this=$this->input->post('inputsearchbranch');

        $limit = 20;
        $data['fields'] = array(
            'branch_name' => 'Branch Name',
            'city'=>'City',
            'district'=>'District',
            'tahsil'=>'Tahsil',
            'Branch_manager'=>'Branch Manager'
                );

        $this->load->model('mod_user');
        $searchbranch=$this->mod_user->search_branch($search_this,$limit);
        $data['searchbranch'] = $searchbranch;

        $config = array();
        $config['base_url'] = site_url("ctl_home/search_branch/");
        $config['total_rows'] = count($searchbranch);
        $config['per_page'] = $limit;
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();

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

My view:

<center>
    <form class="userinfo" action="" method="post">
        //table in which search record display
    </form>
</center>
    <?php if (strlen($pagination)): ?>
<div class="pagination">
    <?php echo $pagination; ?>
</div>
<?php endif; ?>
3
What is you url for second page?? - Pathik Gandhi
@PathikGandhi: http://localhost/kccs/index.php/ctl_dbcont/receipts/receipt_date/asc/20 it seems wrong . . - Jay
can you post the model for your search_branch? maybe the problem lies there. - pat

3 Answers

0
votes

Try to changing the "$config['uri_segment'] = 3;" to $config['uri_segment'] = 5;

And you are count the total count with the limited record. The total count value will be counted with all records.

0
votes
   function search_branch()
{
        $this->load->library('pagination');
        $search_this=$this->input->post('inputsearchbranch');

        $limit = 20;
        $data['fields'] = array(
            'branch_name' => 'Branch Name',
            'city'=>'City',
            'district'=>'District',
            'tahsil'=>'Tahsil',
            'Branch_manager'=>'Branch Manager'
                );

        $this->load->model('mod_user');
        $searchbranch=$this->mod_user->search_branch($search_this,false);
        $config['total_rows'] = count($searchbranch);

        $searchbranch=$this->mod_user->search_branch($search_this,$limit);
        $data['searchbranch'] = $searchbranch;

        $config = array();
        $config['base_url'] = site_url("ctl_home/search_branch/");

        $config['per_page'] = $limit;
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();

        $this->load->view('view_searchbranch',$data);
}
0
votes

& also use

$offset = $this->uri->segment(4);

Add new parameter to search_branch function and pass that to db..

$searchbranch=$this->mod_user->search_branch($search_this,$limit,$offset);

example Function($where,$limit,$offset)

         $this->db->where($where);
$query = $this->db->get('mytable', $limit, $offset);