title: Codeigniter Pagination: Error Autoincrement Number
body: <p>I have error pagination and just read this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/21116050/incrementing-operator-in-foreach-loop-for-pagination">Incrementing Operator in Foreach Loop for Pagination</a></p>
  
  <p>Its working when my pagination is <strong>active</strong>. When my pagination is <strong>inactive</strong>, my web has bugs on auto increment number. Here's the picture:</p>
  
  <p><a href="https://i.stack.imgur.com/i28RR.png" rel="nofollow noreferrer">Page when my pagination is inactive</a></p>
  
  <p><a href="https://i.stack.imgur.com/E5F95.png" rel="nofollow noreferrer">Page when my pagination is active</a></p>
  
  <p>Here's my model:</p>
  
  <pre><code>public function countGate()
    {
        return $this-&gt;db-&gt;count_all_results("tbl_gate");
    }
  
    public function paginationGate($limit, $start)
    {
        $this-&gt;db-&gt;select('*');
        $this-&gt;db-&gt;from('tbl_gate');
        $this-&gt;db-&gt;limit($limit, $start);
        return $this-&gt;db-&gt;get();
    }
  </code></pre>
  
  <p>Here's my controller:</p>
  
  <pre><code>public function gate()
    {
        $this-&gt;load-&gt;view('template/header');
        $this-&gt;load-&gt;view('admin/admin-header');
  
        $config = array();
        $config["base_url"] = base_url() . "index.php/admin/gate";
        $config["total_rows"] = $this-&gt;pagination_m-&gt;countGate();
        $config["per_page"] = 8;
        $config["uri_segment"] = 3;
  
        $this-&gt;pagination-&gt;initialize($config);
        $page = ($this-&gt;uri-&gt;segment(3)) ? $this-&gt;uri-&gt;segment(3) : 0;
        $data['allgate'] = $this-&gt;pagination_m-&gt;paginationGate($config["per_page"], $page);
        $data['links'] = $this-&gt;pagination-&gt;create_links();
  
        $this-&gt;load-&gt;view('admin/admin-gate', $data);
        $this-&gt;load-&gt;view('template/footer');
    }
  </code></pre>
  
  <p>Here's my view (table with autoincrement minus bug):</p>
  
  <pre><code>&lt;table class="table table-bordered"&gt;
          &lt;tr&gt;
            &lt;th&gt;#&lt;/th&gt;
            &lt;th&gt;Fullname&lt;/th&gt;
            &lt;th&gt;Gate&lt;/th&gt;
            &lt;th&gt;Password&lt;/th&gt;
            &lt;th&gt;Access&lt;/th&gt;
            &lt;th&gt;Active&lt;/th&gt;
            &lt;th colspan="2"&gt;Action&lt;/th&gt;
          &lt;/tr&gt;
          &lt;?php
            $i = 1 + ($this-&gt;pagination-&gt;cur_page-1)*$this-&gt;pagination-&gt;per_page;
            foreach ($allgate-&gt;result() as $gate){
          ?&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;?= $i++ ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?= $gate-&gt;Fullname ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?= $gate-&gt;Username ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?= $gate-&gt;Password ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?= $gate-&gt;Level ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?= $gate-&gt;Active ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href="&lt;?= site_url('AdminUpdate/updateGate/'.$gate-&gt;IdGate)?&gt;" data-toggle="modal" data-target="#update-gate"&gt;Edit&lt;/a&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href="&lt;?= site_url('admindelete/deletegate/'.$gate-&gt;IdGate)?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php } ?&gt;
        &lt;/table&gt;
  </code></pre>