Welcome Guest, Not a member yet? Register   Sign In
Help Required for Pagination
#1

[eluser]Unknown[/eluser]
I have been developing a simple page, & stuck with pagination issue. Following are the code details.

It works fine for the only first page, then category id is being replaced by page number. Some people in this forum says, put $category_id into session, but putting this into session create another issue that when user left the page, and want to browse another category but previous category id still exists into session.

Your help will be highly appreciated.

I have displayed no. of categories & they have posts.

Category display code.

Code:
<?php
      foreach ($category->result_array() as $row)
      {
       $id = $row['id'];
       echo "<li>";
       echo "<a href='/reading/index.php/category/browse/$id'>";
       echo $row['name'];
       echo "</a></li>";
      }
      ?&gt;

Code for displaying category posts.

Code:
public function browse($id)
{

  echo $id;
  
  $data['base']=$this->config->item('base_url');
  $this->load->library('pagination');
  $this->load->library('table');
  
  $total=$this->db->get_where('content', array('category_id_FK' => $catid))->num_rows();
  $offset=$this->uri->segment(3);
  $per_pg=2;

  
  $config['base_url'] = $data['base'].'/index.php/category/browse/';
  $config['total_rows'] = $total;
  $config['per_page']='10';
  $config['num_links']='10';
  
  $config['next_link'] = 'Next &gt;';
  $config['prev_link'] = '&lt; Previous ';
  $config['page_query_string'] = FALSE;
  
  $config['full_tag_open'] = '<div id="pagination">';
  $config['full_tag_close'] = '</div>';
  
  $this->pagination->initialize($config);
  
  $data['pagination']=$this->pagination->create_links();
  
  $query = $this->db->get_where('content', array('category_id_FK' => $catid), $per_pg,$offset);
  
  $data['category'] = $query;
  
  $this->load->view('category',$data);
  
}




Theme © iAndrew 2016 - Forum software by © MyBB