This is my first time doing pagination. Everything working fine except the the 1 2 3.... link part on my view. The result from database also showing perfectly. But whenever I click on the 2 it leads to a 404 page.
My view link: http://localhost/learn/site/index/ When I click on the 2 : http://localhost/learn/site/index/10
My controller:
public function index(){
$this->load->model('model_users');
//--------------------Pagination----------------------
$this->load->library('pagination');
$config['base_url'] = base_url().'site/index'; ;
$config['total_rows'] = $this->db->get('posts')->num_rows();
$config['uri_segment'] = 3;
$config['per_page'] = 10;
$this->pagination->initialize($config);
$pag = $this->db->order_by("post_id", "desc")->get('posts', $config['per_page'], $this->uri->segment(3));
$table_data_home['allposts'] = $pag->result();
//------------end pagination-------------------------
$this->load->view('my_site',$table_data_home);
}`
Here is my view:
<?php
foreach($allposts as $posts){
$title = $posts->post_title;
$name = $posts->name;
$categories = $posts->category;
$post = $posts->post;
$pic = $posts->pic;
$time = $posts->time;
$post_id = $posts->post_id;
?>
<div id="allsinglepost"> <a href="<?php echo site_url('site/full_post'); ?>?post_id=<?php echo $post_id ?>">
<h3><?php echo $title;?></h3>
</a>
<hr class="post_inside_hr">
<h6><b>Written By :</b> <?php echo $name ;?></h6>
<h6><b>Date:</b>
<?php echo substr($time,0,10).'; Time: '.substr($time,11,12); ?>
</h6>
<hr class="post_inside_hr">
<div id="post_description">
<p><?php echo substr($post,0,200) ;?> ........</p>
</div>
</div>
<hr id="postbreakline">
<?php } ?>
<!--The upper part will be a FOREACH for posts-->
<!-- pagination part -->
<?php
echo $this->pagination->create_links();
?>
Can anyone tell me where is the problem? I am stuck here.
$config['base_url'] = base_url().'site/index'; ;as$config['base_url'] = site_url('site/index');- Rejoanul Alam