Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter pagination error (offset)
    primarykey
    data
    text
    <p>Right, using pagination for the first time and CANNOT get it to work beyond the first page (404 error). It all seems to revolve around the $offset variable as if I change the offset's variable to an integer (such as 15), it displays the results on the first page from row 15 onwards - but the $this->uri->segment(2) variable is just not working. It all displays correctly, but second page won't load (as I said, 404 error).</p> <p>Controller:</p> <pre><code>&lt;?php class Brands extends CI_Controller { public function index() { $this-&gt;load-&gt;library('pagination'); $config['base_url'] = base_url() . '/brands/'; $config['total_rows'] = $this-&gt;db-&gt;count_all('seixweb'); $config['per_page'] = 15; $limit = $config['per_page']; $offset = $this-&gt;uri-&gt;segment(2); $this-&gt;pagination-&gt;initialize($config); $this-&gt;load-&gt;model('Default_model'); ... Etc. } } </code></pre> <p>Model:</p> <pre><code>&lt;?php class Default_model extends CI_Model { function get_list($limit, $offset) { $query = $this-&gt;db-&gt;get('tbl', $limit, $offset); return $query-&gt;result_array(); } } </code></pre> <p>URL (first page):</p> <pre><code>http://www.mydomain.com/brands </code></pre> <p>URL (second page):</p> <pre><code>http://www.mydomain.com/brands/15 </code></pre> <p>What am I doing wrong?</p> <p>Although it will have nothing to do with the error, view:</p> <pre><code> &lt;!-- Products --&gt; &lt;div class="products"&gt; &lt;div class="cl"&gt;&amp;nbsp;&lt;/div&gt; &lt;p&gt;&lt;?=$this-&gt;pagination-&gt;create_links();?&gt;&lt;/p&gt; &lt;div class="cl"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt;&lt;!-- End Products --&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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