title: Output a count number in foreach loop to show proper row number
body: <p>What's the best practice to output the each row's real counter from an array ? I have the object array of retrieved users from database that I'am echoing into the <code>&lt;table /&gt;</code></p>
  
  <pre><code>&lt;tbody&gt;
      &lt;?php $i = 1;?&gt;
      &lt;?php foreach($members as $member):?&gt;
      &lt;tr&gt;
          &lt;td class="column-counter"&gt;
              &lt;?php echo $i;?&gt;
          &lt;/td&gt;
          &lt;td class="column-check"&gt;
              &lt;input type="checkbox" class="checkbox" name="checked[]" value="&lt;?php echo $member-&gt;id;?&gt;" &lt;?php if(intval($member-&gt;id) === intval($this-&gt;session-&gt;userdata('login_status')['id'])):?&gt;disabled&lt;?php endif;?&gt;&gt;
          &lt;/td&gt;
          &lt;td class="column-username"&gt;
              &lt;?php echo $member-&gt;username;?&gt;
          &lt;/td&gt;
          &lt;td class="column-email"&gt;
              &lt;a href="#send-email"&gt;&lt;?php echo $member-&gt;email;?&gt;&lt;/a&gt;
          &lt;/td&gt;
          &lt;td class="column-id"&gt;
              &lt;?php echo $member-&gt;id;?&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php $i++;?&gt;
      &lt;?php endforeach;?&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>What I've done so far is that <code>$i =1</code> incrementing each time the loop is triggered.</p>
  
  <p>But the problem is that if I go to the second page, it starts from "1" again, instead of let's say <code>21</code> (in case it shows 20 rows per page).</p>
  
  <p>How can I make it right so it will continue counting from last row of previous page ?</p>
  
  <p>By the way I'am using a codeigniter if that helps.</p>
  
  <p><strong>==== UPDATE ====</strong></p>
  
  <p>The model <code>models/members_model.php</code> i'am using in <code>controllers/members.php</code> to retrieve the users holds this function mixed with pagination:</p>
  
  <pre><code>public function members($data = array(), $return_count = FALSE){
  
      $this-&gt;db
          -&gt;select('
              members.id,
              categories.title as role,
              members.catid as role_id,
              members.firstname,
              members.lastname,
              members.username,
              members.email,
              members.status,
              members.image
          ')
          -&gt;join('categories', 'members.catid = categories.id');
  
      if( empty($data) ){
          // If nothing provided, return everything
          $this-&gt;get_members();
      }else{
          // Grab the offset
          if( !empty($data['page']) ){
              $this-&gt;db-&gt;offset($data['page']);
          }
  
          // Grab the limit
          if( !empty($data['items']) ){
              $this-&gt;db-&gt;limit($data['items']);
          }
  
          if( $return_count ){
              return $this-&gt;db-&gt;count_all_results($this-&gt;_table_name);
          }else{
              return $this-&gt;db-&gt;get($this-&gt;_table_name)-&gt;result();
          }
      }
  
  }
  </code></pre>