0

検索結果ページにページネーションを実装しようとしています。私は昨日この質問をしましたが、コードイグナイターのページネーションを使用して検索ページに制限されていません。

私が今抱えている問題は少し異なります。

状況

私のページネーション リンクは機能しており、次のように URL が変更されていることがわかります: http://example.com/home/searchresults/2 (ページネーションの 2 ページ目) など。しかし、すべての検索結果が表示されます。制限を 1 に編集すると、より多くのリンクが取得されるため、適切に機能しています。

質問

この愚かな問題は何でしょうか?私のTotal_rowsに関係していると思います

私のコントローラー:

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

        $limit = 4;
        $offset=($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $config['base_url'] = base_url().'home/searchresults/';
        $config['total_rows'] = count($this->bedrijven_model->get_search($match, $match2, $limit, $offset ));
        $config['per_page'] = $limit;
        $config['use_page_numbers'] = TRUE;
        $config['num_links'] = 5;   

        $this->pagination->initialize($config);
        $offset = $this->uri->segment(3);
        $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=0)
{
    if(!isset($_SESSION)) 
    { 
    session_start();
    };
    /*
    $string = implode($_SESSION['postcodes'], '|');
    $string2 = $_SESSION['searched_post_code'];
    */
    $postcodes = (is_array($_SESSION['postcodes']) ? $_SESSION['postcodes'] : array());
    $postcodes[] =  $_SESSION['searched_post_code'];
    $postcodes = array_filter(filter_var_array($postcodes, FILTER_VALIDATE_INT));
    $string = join(',', $postcodes);

        if (!isset($_COOKIE['cookie'])) { 

            $query = "SELECT * FROM (`bedrijfcategorieen`) 
            JOIN `bedrijven` ON `bedrijfcategorieen`.`idbedrijven` = `bedrijven`.`idbedrijven` 
            JOIN `categorieen` ON `bedrijfcategorieen`.`idcategorieen` = `categorieen`.`idcategorieen` 
            WHERE (`Bedrijfsnaam` LIKE '%".$this->input->post('search')."%' 
            OR `Plaats` LIKE '%".$this->input->post('search')."%' 
            OR `Telefoonnummer` LIKE '%".$this->input->post('search')."%' 
            OR `Email` LIKE '%".$this->input->post('search')."%' 
            OR `Website` LIKE '%".$this->input->post('search')."%' 
            OR `Profiel` LIKE '%".$this->input->post('search')."%' 
            OR `Adres` LIKE '%".$this->input->post('search')."%' 
            OR `Categorie` LIKE '%".$this->input->post('search')."%') 
            AND (Postcode IN ($string))

            GROUP BY `Categorie`,  `bedrijfcategorieen`.`idbedrijven`";
            $query = $this->db->query($query);
            $this->db->limit($limit, $offset);
            echo '<pre>';
            echo '</pre>';
            $result = $query->result_array();
            return $result;
      }

誰かがこれで私を助けてくれることを願っています。私は今、これにほぼ3時間苦労しています。

4

2 に答える 2

1

文字列内に制限/オフセットが必要です$query:

$query = "SELECT * FROM (`bedrijfcategorieen`) 
        JOIN `bedrijven` ON `bedrijfcategorieen`.`idbedrijven` = `bedrijven`.`idbedrijven` 
        JOIN `categorieen` ON `bedrijfcategorieen`.`idcategorieen` = `categorieen`.`idcategorieen` 
        WHERE (`Bedrijfsnaam` LIKE '%".$this->input->post('search')."%' 
        OR `Plaats` LIKE '%".$this->input->post('search')."%' 
        OR `Telefoonnummer` LIKE '%".$this->input->post('search')."%' 
        OR `Email` LIKE '%".$this->input->post('search')."%' 
        OR `Website` LIKE '%".$this->input->post('search')."%' 
        OR `Profiel` LIKE '%".$this->input->post('search')."%' 
        OR `Adres` LIKE '%".$this->input->post('search')."%' 
        OR `Categorie` LIKE '%".$this->input->post('search')."%') 
        AND (Postcode IN ($string)) 
        GROUP BY `Categorie`,  `bedrijfcategorieen`.`idbedrijven` 
        LIMIT ".$offset.", ".$limit;

       $result = $this->db->query($query);
       return $result->result_array();
于 2013-05-28T10:49:17.850 に答える
0

$this->db->limitアクティブなレコードでのみ機能します。とにかく、クエリをこれに変更してください

$query = "SELECT * FROM (`bedrijfcategorieen`) 
        JOIN `bedrijven` ON `bedrijfcategorieen`.`idbedrijven` = `bedrijven`.`idbedrijven` 
        JOIN `categorieen` ON `bedrijfcategorieen`.`idcategorieen` = `categorieen`.`idcategorieen` 
        WHERE (`Bedrijfsnaam` LIKE '%".$this->input->post('search')."%' 
        OR `Plaats` LIKE '%".$this->input->post('search')."%' 
        OR `Telefoonnummer` LIKE '%".$this->input->post('search')."%' 
        OR `Email` LIKE '%".$this->input->post('search')."%' 
        OR `Website` LIKE '%".$this->input->post('search')."%' 
        OR `Profiel` LIKE '%".$this->input->post('search')."%' 
        OR `Adres` LIKE '%".$this->input->post('search')."%' 
        OR `Categorie` LIKE '%".$this->input->post('search')."%') 
        AND (Postcode IN ($string))
        GROUP BY `Categorie`,  `bedrijfcategorieen`.`idbedrijven`
        LIMIT $offset,$limit";
        $query = $this->db->query($query);

もう1つ、 $this->db->limit を使用する必要はありません

于 2013-05-28T12:36:42.070 に答える