Note that there are some explanatory texts on larger screens.

plurals
  1. PO$offset not working for pagination codeigniter
    primarykey
    data
    text
    <p>I am trying to implement Pagination into my searchresults page. I've asked this question yesterday with no succes <a href="https://stackoverflow.com/questions/16775206/records-not-limited-on-searchpage-using-codeigniter-pagination">Records not limited on searchpage using codeigniter pagination</a></p> <p>and the problem I have now is a bit different.</p> <p><strong>Situation</strong></p> <p>My pagination links are working and i see the url change like this: <a href="http://example.com/home/searchresults/2" rel="nofollow noreferrer">http://example.com/home/searchresults/2</a> (for the second page of pagination) etc. But all the searchresults are shown. When I edit the limit to 1 I get more links, so that's working properly.</p> <p><strong>Question</strong></p> <p>What could be this stupid problem? I think it has to do with my Total_rows</p> <p>My controller:</p> <pre><code> function searchresults() { $this-&gt;breadcrumbs-&gt;page = array('link'=&gt; base_url().'home/search' ,'title' =&gt; 'Bedrijven Zoeken' ); $this-&gt;breadcrumbs-&gt;method = array('link'=&gt; base_url().'home/searchresults' ,'title' =&gt; 'Zoekresultaten' ); $data['breadcrumbs'] = $this-&gt;breadcrumbs-&gt;get(); $match = $this-&gt;input-&gt;post('search'); if(strlen($this-&gt;input-&gt;post('cookie')) &gt; 0){ $match2 = $this-&gt;input-&gt;post('cookie'); } else{ $match2 = '9101'; } $this-&gt;load-&gt;library('pagination'); $limit = 4; $offset=($this-&gt;uri-&gt;segment(3)) ? $this-&gt;uri-&gt;segment(3) : 0; $config['base_url'] = base_url().'home/searchresults/'; $config['total_rows'] = count($this-&gt;bedrijven_model-&gt;get_search($match, $match2, $limit, $offset )); $config['per_page'] = $limit; $config['use_page_numbers'] = TRUE; $config['num_links'] = 5; $this-&gt;pagination-&gt;initialize($config); $offset = $this-&gt;uri-&gt;segment(3); $data['links'] = $this-&gt;pagination-&gt;create_links(); //$data['query'] = $this-&gt;bedrijven_model-&gt;get_search($match, $match2, 2147483647, 0); /*large number as limit to retrieve all the rows*/ $data['query_curr'] = $this-&gt;bedrijven_model-&gt;get_search($match, $match2, $config['per_page'], $this-&gt;uri-&gt;segment(3) ); $this-&gt;load-&gt;view('views/header'); $this-&gt;load-&gt;view('views/searchresults', $data); $this-&gt;load-&gt;view('views/footer'); } </code></pre> <p>My model:</p> <pre><code>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-&gt;input-&gt;post('search')."%' OR `Plaats` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Telefoonnummer` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Email` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Website` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Profiel` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Adres` LIKE '%".$this-&gt;input-&gt;post('search')."%' OR `Categorie` LIKE '%".$this-&gt;input-&gt;post('search')."%') AND (Postcode IN ($string)) GROUP BY `Categorie`, `bedrijfcategorieen`.`idbedrijven`"; $query = $this-&gt;db-&gt;query($query); $this-&gt;db-&gt;limit($limit, $offset); echo '&lt;pre&gt;'; echo '&lt;/pre&gt;'; $result = $query-&gt;result_array(); return $result; } </code></pre> <p>I hope someone can help me with this. I am struggling with this for almost 3 hours now.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload