$offset not working for pagination codeigniter

后端 未结 2 2001
轻奢々
轻奢々 2021-01-26 00:32

I am trying to implement Pagination into my searchresults page. I\'ve asked this question yesterday with no succes Records not limited on searchpage using codeigniter pagination

相关标签:
2条回答
  • 2021-01-26 00:53

    $this->db->limit only works with active records. Anyway, change your query to this

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

    One more thing, no need to use $this->db->limit

    0 讨论(0)
  • 2021-01-26 01:10

    You need your limit/offset inside the $querystring:

    $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();
    
    0 讨论(0)
提交回复
热议问题