记录不使用笨分页上searchpage限制(Records not limited on searc

2019-10-18 04:58发布

情况

我有一个重定向到我想要实现笨分页一个SearchResult所页面searchform。 我的极限是行不通的。 因此,所有的结果显示,而不是我的$limit = 4;

这里是我的控制器代码:

    function searchresults()
    {   

        $this->breadcrumbs->page = array('link'=> base_url().'home/search' ,'title' => 'Bedrijven Zoeken' );            
        $this->breadcrumbs->method = array('link'=> base_url().'home/searchresults' ,'title' => 'Zoekresultaten' );
        $data['breadcrumbs'] = $this->breadcrumbs->get();
        $match = $this->input->post('search');
        if(strlen($this->input->post('cookie')) > 0){ $match2 = $this->input->post('cookie'); } else{ $match2 = '9101'; }
        $data['query'] = $this->bedrijven_model->get_search($match, $match2);

        $limit = 4;
        $this->load->library('pagination');
        $config['base_url'] = base_url().'home/searchresults/';
        $config['total_rows'] = count($data['query']);
        $config['per_page'] = $limit;
        $config['uri_segment'] = 3;

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

        $data['links'] = $this->pagination->create_links();
        $this->load->view('views/header');
        $this->load->view('views/searchresults', $data);
        $this->load->view('views/footer');
    }

可能是什么问题呢? 我缺少的东西吗?


编辑

我仍然无法得到它的工作。 这是我到目前为止所。

控制器:

    function searchresults()
    {   

        $this->breadcrumbs->page = array('link'=> base_url().'home/search' ,'title' => 'Bedrijven Zoeken' );            
        $this->breadcrumbs->method = array('link'=> base_url().'home/searchresults' ,'title' => 'Zoekresultaten' );
        $data['breadcrumbs'] = $this->breadcrumbs->get();
        $match = $this->input->post('search');
        if(strlen($this->input->post('cookie')) > 0){ $match2 = $this->input->post('cookie'); } else{ $match2 = '9101'; }
        $this->load->library('pagination');
        $config['base_url'] = base_url().'home/searchresults/';
        $config['per_page'] = 4;

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

        $data['links'] = $this->pagination->create_links();
        //$data['query'] = $this->bedrijven_model->get_search($match, $match2, 2147483647, 0); /*large number as limit to retrieve all the rows*/           
        $data['query_curr'] = $this->bedrijven_model->get_search($match, $match2, $config['per_page'], $this->uri->segment(3) );
        $this->load->view('views/header');
        $this->load->view('views/searchresults', $data);
        $this->load->view('views/footer');
    }

模型:

function get_search($match, $match2, $limit, $offset)
{
    $this->db->limit($limit, $offset);
            //rest of the code
    }

我的观点:

    <?php foreach($query_curr as $item):?>
    <br/>
    <div class="logo1">
    <a href="<?php echo base_url()?>bedrijven/<?= $item['idbedrijven'] ?>"><img src="http://i.ebayimg.com/t/Aluminum-Body-Violin-or-Cello-Makers-Compass-Draw-Shave-Plane-Good-Shape-/00/s/NDYwWDU1MQ==/$(KGrHqJ,!hYF!sl)RwymBQiLq5Cn4Q~~60_35.JPG"></a>
    </div>
        <a href="<?php echo base_url()?>bedrijven/<?= $item['idbedrijven'] ?>"><h3><?= $item['Bedrijfsnaam']   ?></h3></a>
        <p>
        <b>Categorie:</b>
        <?php echo "" . $item['Categorie'] . ", &nbsp;" ; ?>
        </p>
        <small>
            <p><b><?php echo $item['Email'] ?></b></p>
            <p><b>Postcode:</b> <?php echo $item['Postcode'] ?></p>
            <p><b>Plaats:</b> <?php echo $item['Plaats'] ?></p>
            <p><b>Tags:</b></p>
            <p><?php echo $item['Profiel'] ?></p>   
        </small>
        <br/><hr/>
    <?php endforeach;?>
    <br/>
    <?= $this->pagination->create_links(); ?>
    <br />
    <br />

Answer 1:

你必须设置偏移和限制,当你从数据库中查询到使拼版作业。

您get_search模型应该是这样的

function get_search($match, $match2, $limit, $offset){
    $this->db->limit($limit, $offset);
    /*Rest of the code*/
}

您当前的查询变得

$data['query'] = $this->bedrijven_model->get_search($match, $match2, 2147483647, 0); /*large number as limit to retrieve all the rows*/

您需要查询其他时间偏移和限制这样的

$data['query_curr'] = $this->bedrijven_model->get_search($match, $match2, $config['per_page'], $this->uri->segment(3) );

在这里,$配置[“per_page”]是极限,从URL段采取的偏移量(你必须初始化URL帮手。你需要使用这个query_curr视图中的变量,这是使用分页和正确数量的方式行的将被显示。

最后一件事,你不必送create_links()作为视图变量。 您可以在视图中直接使用。

更新:

改变你的searchresult功能,这

function searchresults()
{   

    $this->breadcrumbs->page = array('link'=> base_url().'home/search' ,'title' => 'Bedrijven Zoeken' );            
    $this->breadcrumbs->method = array('link'=> base_url().'home/searchresults' ,'title' => 'Zoekresultaten' );
    $data['breadcrumbs'] = $this->breadcrumbs->get();
    $match = $this->input->post('search');
    if(strlen($this->input->post('cookie')) > 0){ $match2 = $this->input->post('cookie'); } else{ $match2 = '9101'; }
    $data['query'] = $this->bedrijven_model->get_search($match, $match2, 2147483647, 0);
    $this->load->library('pagination');
    $config['base_url'] = base_url().'home/searchresults/';
    $config['total_rows'] = count($data['query']);
    $config['per_page'] = 4;

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

    $data['links'] = $this->pagination->create_links();
    //$data['query'] = $this->bedrijven_model->get_search($match, $match2, 2147483647, 0); /*large number as limit to retrieve all the rows*/           
    $data['query_curr'] = $this->bedrijven_model->get_search($match, $match2, $config['per_page'], $this->uri->segment(3) );
    $this->load->view('views/header');
    $this->load->view('views/searchresults', $data);
    $this->load->view('views/footer');
}


文章来源: Records not limited on searchpage using codeigniter pagination