i have made codeigniter pagination to show my product in image. but something is wrong on the second page, it is not sustainable or continuously.
i set per_page is: 6, my total data is 11.
in page 1 result is ok, show image by id form 1 - 6,but when i click second page the start from 3 - 8.
this is the model
public function record_count()
{
return $this->db->count_all('mytable');
}
public function fetch_jenislogam($limit, $start)
{
$start--;
if($start<0)
{
$start=0;
}
$this->db->limit($limit, $start);
$query = $this->db->get("tb_jenislogam");
return $query->result_array();
}
this is my view
<?php
foreach($results as $data) { ?>
<div class="col-lg-3 text-center">
<a href="<?php echo base_url();?>item/subitem/<?php echo $data->id; ?>"> <!-- to direct product subitem -->
<img class="img-responsive" src='<?php $img = $data->pics;
if ($img) {
echo base_url().'uploads/origin/'.$data->pics;
} else {
echo base_url().'uploads/origin/def-img.png';
}
?>'></a>
<br>
</div>
<div>
<?php echo $data->id;?></div>
<?php
}
?>
and this the controller look like.
public function listitem()
{
$config = array();
$config['base_url'] = base_url().'item/listitem';
$config['total_rows'] = $this->item_m->record_count();
$config['per_page'] = 6;
$config['uri_segment'] = 3;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$config['cur_tag_open'] = '<a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = '>';
$config['prev_link'] = '<';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['links'] = $this->pagination->create_links();
$data['uri'] = $this->uri->segment(3);
$data['results'] = $this->item_m->fetch_jenislogam($config['per_page'], $page);
$this->load->view('user_header');
$this->load->view('user/usr_item_view', $data);
$this->load->view('user_footer');
}