Reputation: 589
I have tried lots of code from tutorial but when I click on the pagination it keeps showing me the same data. I am using AdminLTE theme. Maybe thats the problem
Controller
public function view_blog()
{
$this->load->model("blog_model");
$this->load->library("pagination");
$config = array();
$config["base_url"] = base_url() . "blog/Blog/view_blog/";
$config["total_rows"] = $this->blog_model->count_blog();
$config["per_page"] = 2;
$config["uri_segment"] = 5;
$this->pagination->initialize($config);
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
$data["view_data"] = $this->blog_model->view_data($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data['view'] = 'blog_view/view_blog';
$this->load->view('admin/layout', $data);
}
Model
public function view_data($limit,$start)
{
$query= $this->db->get("blog", $limit, $start);
return $query->result();
}
public function count_blog(){
return $this->db->count_all("blog");
}
View
<div class="content">
<?php
foreach ($view_data as $row){
echo' <div class="row">
....
</div>';
}
?>
<?php echo $links; ?>
</div>
When I click on page 2 the next two blog should appear
Upvotes: 0
Views: 80
Reputation: 74
In controller:
If $config["base_url"] = base_url() . "blog/Blog/view_blog/";
exactly.
Change 1
> $config["uri_segment"] = 5;
to
> $config["uri_segment"] = 4;
Change 2
> $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
to
> $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
Upvotes: 1
Reputation: 221
Try $config["uri_segment"] = 4;
instead of $config["uri_segment"] = 5;
I would check that 5 is the correct offset for the page number of your uri segment. According to the URI documentation, 1 is the first segment after your base_url(). If you are following the defaults of the Pagination Class, the page number will be immediately after your configured base_url in the class. Since your $config['base_url'] is set to "blog/Blog/view_blog/", the correct $config['uri_segment'] would be 4 and not 5.
You would also want to change $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
to $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
Upvotes: 1