在foreach循环中输出计数数字以显示正确的行号

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 <table />

<tbody>
    <?php $i = 1;?>
    <?php foreach($members as $member):?>
    <tr>
        <td class="column-counter">
            <?php echo $i;?>
        </td>
        <td class="column-check">
            <input type="checkbox" class="checkbox" name="checked[]" value="<?php echo $member->id;?>" <?php if(intval($member->id) === intval($this->session->userdata('login_status')['id'])):?>disabled<?php endif;?>>
        </td>
        <td class="column-username">
            <?php echo $member->username;?>
        </td>
        <td class="column-email">
            <a href="#send-email"><?php echo $member->email;?></a>
        </td>
        <td class="column-id">
            <?php echo $member->id;?>
        </td>
    </tr>
    <?php $i++;?>
    <?php endforeach;?>
</tbody>

What I've done so far is that $i =1 incrementing each time the loop is triggered.

But the problem is that if I go to the second page, it starts from "1" again, instead of let's say 21 (in case it shows 20 rows per page).

How can I make it right so it will continue counting from last row of previous page ?

By the way I'am using a codeigniter if that helps.

==== UPDATE ====

The model models/members_model.php i'am using in controllers/members.php to retrieve the users holds this function mixed with pagination:

public function members($data = array(), $return_count = FALSE){

    $this->db
        ->select('
            members.id,
            categories.title as role,
            members.catid as role_id,
            members.firstname,
            members.lastname,
            members.username,
            members.email,
            members.status,
            members.image
        ')
        ->join('categories', 'members.catid = categories.id');

    if( empty($data) ){
        // If nothing provided, return everything
        $this->get_members();
    }else{
        // Grab the offset
        if( !empty($data['page']) ){
            $this->db->offset($data['page']);
        }

        // Grab the limit
        if( !empty($data['items']) ){
            $this->db->limit($data['items']);
        }

        if( $return_count ){
            return $this->db->count_all_results($this->_table_name);
        }else{
            return $this->db->get($this->_table_name)->result();
        }
    }

}

It sounds like $data['page'] holds the information you need since this is related to the specified offset. You didn't reference the name of this array in your global scope, so I will just call this $data_array in my answer.

You can determine the starting value for $i as follows

$i = $data_array['page'] + 1;