分页链接在第二页 - codeigniter上消失

时间:2013-04-23 04:35:28

标签: php codeigniter pagination

嘿,伙计们。我的Codeigniter项目中有分页问题。我正在使用分页库,我有一个搜索表单。当我搜索某些内容时,结果会显示在页面上。当结果行超过限制时,我会显示分页链接。但是当我点击第2个链接转到第二页时,分页链接就会消失。我的搜索代码如下...

控制器功能:

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);
}

我的观点:

<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 个答案:

答案 0 :(得分:0)

尝试将"$config['uri_segment'] = 3;"更改为$config['uri_segment'] = 5;

你用有限的记录计算总数。总计数值将与所有记录一起计算。

答案 1 :(得分:0)

   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);
}

答案 2 :(得分:0)

&安培;也用

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

将新参数添加到search_branch函数并将其传递给db ..

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

示例函数($ where,$ limit,$ offset)

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