0

大家好。我的 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; ?>
4

3 回答 3

0

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

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

于 2013-04-23T04:41:16.933 回答
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);
}
于 2013-04-23T04:41:20.330 回答
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);
于 2013-04-23T04:56:14.127 回答