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