0

我的 codeigniter 项目中有一个搜索功能。

搜索使用连接在多个表中进行搜索。现在是我的问题:如何向该搜索表单添加分页,以便在一页上显示 5 个结果。

我的搜索功能

function searchresults()
{
    $match = $this->input->post('search');
    $data['query'] = $this->bedrijven_model->get_search($match);
    $this->load->view('views/header');
    $this->load->view('views/searchresults', $data);
    $this->load->view('views/footer');
    $data['query'] = $this->bedrijven_model->bedrijven_tags();
}

我的搜索视图

<form name="input" action="searchresults" method="post">
<input type="search" placeholder="Zoeken..." name="search">

<input type="submit" value="Zoeken">
<input type="reset" value="Reset">
</form>

<br /><br />

<form method="link" action="<?php echo base_url('home/bedrijven')?>">
<input type="submit" value="Bedrijven">

</form>

我试过的:

    function searchresults()
    {
        $match = $this->input->post('search');
        $data['query'] = $this->bedrijven_model->get_search($match);
        $this->load->library('pagination');
        $config['base_url'] = base_url();
        $config['total_rows'] = 10;
        $config['per_page'] = 5;
        $this->pagination->initialize($config); 
        $this->load->view('views/header');
        $this->load->view('views/searchresults', $data);
        $this->load->view('views/footer');
        $data['query'] = $this->bedrijven_model->bedrijven_tags();
    }

在我看来:echo $this->pagination->create_links();

但它不起作用。

希望可以有人帮帮我 :)

谢谢。

4

2 回答 2

0

首先,$this视图内部与控制器内部不同。(比较这个问题。)我会这样传递分页:

(Controller)
...
$data['pagination'] = $this->pagination->create_links();
...
$this->load->view('views/searchresults', $data);

(View)
<?php echo $pagination; ?>

其次,请记住pagination库只是显示分页的助手。您必须自己调整数据库查询,例如

(Controller)
$skip_entries = $this->uri->segment(2); // or whatever segment it's for you
$this->bedrijven_model->get_search($match, $skip_entries);

(Model)
function get_search($search, $skip_entries)
{  
    ...
    $this->db->limit(5, $skip_entries);
    ...
}
于 2013-04-04T17:24:40.227 回答
0

想要切换到 JS 分页插件这里是链接 [http://www.datatables.net/] 如果您只想显示嵌套数据而没有任何争执,那么我认为这可能会有所帮助。

于 2013-04-04T19:03:21.643 回答