codeigniter pagination not working when there is a query string - codeigniter

i'm using latest version of codeigniter(2.1.4).In admin when i'm sending query string then pagination not working.And i want my url will be like mydomain/commission/user_id/page_no.
ex: mydomain/commission/20/1
Below is my code
$config['per_page'] = 2;
$config['total_rows']=100;
$config['base_url'] = base_url().'admin_vendor/commissions/'.$this->uri->segment(3);
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = FALSE;
$config['enable_query_strings']=FALSE;
$config['num_links'] = 20;
$config['full_tag_open'] = '<ul>';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['next_link'] = 'Next>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '<Prev';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$page = $this->uri->segment(4);
$limit_end = ($page * $config['per_page']) - $config['per_page'];
if ($limit_end < 0){
$limit_end = 0;
}
please guide me. Thanks

go to application/config.php file
and change $config['enable_query_strings'] = FALSE; to
$config['enable_query_strings'] = TRUE;
It will work

Related

CodeIgniter Pagination Links removed after like query executes

`
Controller :
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config = array();
$config['base_url'] = base_url().'tr_admin/billmanagement/';
$config['total_rows'] = $this->bill_model->count_all_bill($this->session->userdata('searchBillRec'));
$config['per_page'] = 100;
$config['use_page_numbers'] = TRUE;
$config["uri_segment"] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['use_page_numbers'] = FALSE;
$config['next_link'] = 'Next';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = ' Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$data['recList'] = $this->bill_model->get_bill($config["per_page"],$page,$this->session->userdata('searchBillRec'));
$this->pagination->initialize($config);
$data['main_content'] = 'tr_admin/billmanagement';
$this->load->view('tr_admin/includes/template', $data);
Model:
if($filterData['bill_to']!=''){
$this->db->like('bill_to', $filterData['bill_to'],'both');
}
$this->db->order_by("bill_id","DESC");
$this->db->limit($per_page,$page);
return $this->db->get()->result_array();
`
Pagination links only show when there's more results than the current offset you set. So if there's only 5 records and your offset is 10 then there's no pagination to do.

Getting the same data on pagination in Codeigniter

I am getting the same data when I am clicking on the next button of pagination in CodeIgniter with the following code
public function view($slug){
$data['title']= $slug;
$data['description']= "None";
$postdatacount = $this->Constant_model->snippettagscount($slug);
$checktags= $this->Constant_model->gettags($slug);
if($checktags>0){
if ($postdatacount>0) {
$config = array();
$config["base_url"] = base_url() ."tags/".$slug;
$config["total_rows"] = $postdatacount;
$config["per_page"] = 6;
$config["uri_segment"] = 2;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["links"] = $this->pagination->create_links();
$data["title"] = "All Tags";
$data["description"] = "All Tags";
$data['snippets_tags'] = $this->Constant_model->get_tags($config["per_page"],$page,$slug);
$this->snippetfunctions->add_count('tags','tag_name',$slug);
$this->load->view('view_tag_snippets', $data);
}else {
$data["title"] = "No Snippet Found for this Tag";
$data["description"] = "No Snippet Found for this Tag";
$data["slug"] =$slug;
$this->load->view('error_tags',$data);
}
}else{
$this->load->view('404',$data);
}
}
Primary URL Made on this function is
http://127.0.0.1/Mytredin_codesup/tags/user-interface
When I am clicking on Next button following URL is made but not loading the next data but loading the same data and the same thing happens on every next page.
http://127.0.0.1/Mytredin_codesup/tags/user-interface/1
Routes I am using is
$route['tags/(:any)/(:num)'] = 'tags/view/$1/$2';
$route['tags/(:any)'] = 'tags/view/$1';
The problem is with the config $config["uri_segment"] = 2;, according to your routing the page variable is at segment 3.
Use $config["uri_segment"] = 3; instead of $config["uri_segment"] = 2;. Also change the line $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
More details read

How to access pagination url without query string in codeigniter?

I want to access pagination URL without query string in CodeIgniter like
http://127.0.0.1/hmvc/business_list/20
Now I am getting URL like
http://127.0.0.1/hmvc/business_list/?p=2
By this I am unable to read the URL segment and pagination is not working fine. It should return 0-10 records on the first page and 10-20 on second page and so on. But in my case, it returns 0-10 on the first page then 2-12 on the second page on the basis of URL segment.
Here is my code:
public function index()
{
$query = $this->db->get('categories','10',$this->uri->segment(2));
$data['results'] = $query->result();
$data['seg'] = $this->uri->segment(2);
$query2 = $this->db->get('categories');
$config['base_url'] = base_url().'business_list/';
$config['total_rows'] = $query2->num_rows();
$config['per_page'] = 10;
// $config['uri_segment'] = $this->uri->segment(2);
// $config['page_query_string'] = false;
$config['page_query_string'] = true;
$config['full_tag_open'] = "<ul class='pagination pagination-right margin-none'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = '<li>';
$config['next_tagl_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tagl_close'] = '</li>';
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['title'] = "Business List";
$this->load->view('categories',$data);
}
How do I rectify this problem?
Use below configuration for pagination
$config['per_page'] = 10;
$config['uri_segment'] = 2;
$config['full_tag_open'] = '<ul class="pagination pagination-right margin-none">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class='disabled'><li class='active'><a href='#'>';
$config['cur_tag_close'] = '<span class='sr-only'></span></a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['enable_query_strings'] = TRUE;

how add this type of pagination (http://my-url.com/search?qry=abc&page=2) in Codigniter

currently i am using this code for pagination in Codigniter
$config['base_url'] = SITEURL. 'search?qry='.$qry.'&';
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '&laquo';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '&raquo';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['total_rows'] = $total_rows;
$config['per_page'] = RECORD_PER_PAGE;
$config['first_url'] = $config['base_url'] . '1' . http_build_query($_GET);
$config['num_links'] = 5;
From what I saw, CodeIgniter's pagination is counting the page wrong way. because I want pagination looking like this:
http://my-url.com/search?qry=abc&page=2
If you don't want to use the noraml uri string gived from CI and you want to use query string (site.com?var1=data&var2=xxx)
you need to change the application/config/config.php file setting the line
158 $config['enable_query_strings'] = FALSE; to TRUE
in your controller to make the pagination get the variables using the normal form
$var1 = $this->input->get('c');
$var2 = $this->input->get('m');
$var3 = $this->input->get('d');

Codeigniter Pagination Need Solution - number link work but page doesnot display as appropriate

I have a problem with pagination in CodeIgniter 2.x
This is my code in Controller:
$config['base_url'] = base_url().'crawl/all/'.$file.'/';
$config['total_rows'] = $total;
$config['per_page'] = 10;
$config['num_links'] = 3;
$config['uri_segment'] = 4;
$config['full_tag_open'] = '<ul id="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['total'] = $total;
$data['path'] = $this->path.'/'.$file;
$data['file'] = $file;
$data['batch'] = $this->batch->all($file, $config['per_page'], $config['uri_segment']);
and my view is just: <?php echo $this->pagination->create_links() ?>
The links for pages numbers work (they move from 1 to 2 etc), but the data does not display correctly.
You are missed out the page id because when you clicks on the page the page no has to send as query string and it has to add for the config.
Example code:
$limit = $this->config->item('paging_limit');
$offset = $id * $limit;
$data['rows'] = $this->news_model->get_moreNews($limit, $offset);
$config["image_url"]=$this->config->item("base_url");
$config['base_url'] = base_url().'/news/morenews/';
$config['total_rows'] = $this->db->count_all('news');
$config['per_page'] = $limit;
$config['chapter'] = $this->input->post('chapter');
$config['page'] = $id;
$this->paginationsimple->initialize($config);
$paginator=$this->paginationsimple->create_links();
$data['paginator'] = $paginator;

Resources