I'm really need your help about pagination.
Already tried to search and not found the answer.
So my problem is my pagination page not show a correct data when I used use_page_number into true.
When I set it to false, my pagination show correct data but the link url not show current page.
With use_page_number is TRUE
Example 1 : per_page is 2;
Page 1 : 1,2
Page 2 : 3,4
Page 3 : 4,5 -> repeated data
Example 2 : per_page is 1
Page 1 : 1
Page 2 : 3 -> this should 2
Page 3 : blank -> this should 3
Example 3 : per_page is 5
Page 1 : 1,2,3,4,5
Page 2 : 3,4,5,6,7
Page 3 : 4,5,6,7,8
With use_page_numbers is false
Page 'blank' : 1,2
Page 2 : 3,4
Page 4 : 5
I know that CI pagination not show current page we are, but need
use_page_numbers (correct me if I'm wrong), but not work in my code :(
I really dont know what's wrong, could you please guys help me to solve it?
This is my code :
$config['base_url'] = base_url()."admin/user/index/";
$config['total_rows'] = $this->db->count_all('msuser');
$config['per_page'] = 3;
$config['num_links'] = 2;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['uri_segment'] = 4;
$config['full_tag_open'] = "<ul class='pagination'>";
$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_link'] = '»';
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_link'] = '«';
$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>";
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$data['user'] = $this->user_model->getUserByPage($config['per_page'], $this->uri->segment(4));
$data['main'] = 'admin/user_view';
$this->load->view('admin/dashboard',$data);
really appreciate for your help guys.
thanks
You can try change a few your code:
$page_num = $this->uri->segment(4);
($page_num>1)? $start = ($page_num - 1) * $config['per_page'] : $start = $page_num;
$data['user'] = $this->user_model->getUserByPage($config['per_page'], $start);
Related
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'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$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
Codeigniter is showing the same data on every page using pagination. I think there is a problem in the URL formed as its unable to get 3rd uri segment from the url.
http://127.0.0.1/hmvc/business_list/?p=2
and the code i used is...
public function index()
{
$query = $this->db->query('SELECT * FROM categories');
$pagination_limit = '10';
$config = array();
$config['base_url'] = base_url().'business_list/';
$config['display_pages'] = true;
$config['first_link'] = 'First';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = $pagination_limit;
$config['uri_segment'] = 3;
$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);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['results'] = $this->Business_model->fetch_comments_data($config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$data['title'] = "Business List";
$this->load->view('categories',$data);
}
Please help.
You need to change this :
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
To
$page = ($this->input->get('p') ? $this->input->get('p') : 0);
I think Codeigniter URI Segment not work in your case because if you url is like that
http://127.0.0.1/hmvc/business_list/page/2
then the first segment is business_list and second is page but you use query string so need to change
Well take a time to understand what are you doing there.
$query = $this->db->query('SELECT * FROM categories');
Looks like you are not defining LIMIT and OFFSET.
i found a nice example about pagination with codeigniter to you.
I have a problem when i do search the pagination number still remains in the url result to showing no resuts. for example when i click a pagination link my url looks like this example/index.php/example/info/10 then when i do search, the url now the url looks like this example/index.php/example/info/10?search=word
How can i fixed this problem
Controller
public function info($offset=0)
{
$this->load->library('pagination');
$search = $this->input->get('search');
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
if($this->input->get('search')){
$count = $this->ticketing_mdl->count_all_ticket();
$config['total_rows'] = $count;
$config['suffix'] = '?' . http_build_query($_GET, '', "&");
$config['base_url'] = "/ticketing/index.php/ticketing/info";
$config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
}else{
$this->db->where('is_valid','1');
$config['total_rows'] = $this->db->count_all_results('db_ticketing.tr_ticket');
$config['base_url'] = "/ticketing/index.php/ticketing/info";
}
$limit = 10;
$config['per_page'] = $limit;
$config['num_links'] = $limit;
$config['full_tag_open'] = '<div><ul class="pagination pagination-centered">';
$config['full_tag_close'] = '</ul></div>';
$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>";
$config['first_link'] = 'First';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['ticket_list'] = $this->ticketing_mdl->get_all_ticket($limit,$page, $offset);
$this->load->view('ticketing/header');
$this->load->view('ticketing/left_menu');
$this->load->view('ticketing/info',$data);
}
Let me know if i am right.
I think you can control it by defining routes.
Set your $config['base_url'] of pagination library like example/index.php/search and define routes (application/config/routes.php) like
$route['search'] = "example/info";
$route['search/(:num)'] = "example/info/$1";
comment this $config['first_url'] = "/ticketing/index.php/ticketing/info?search=$search";
And dont forget to set the html form action="echo site_url('search');" method="get"
I hope this will give you some help.
In codeigniter Pagination ,I have the pagination links like below.
EG 1 : 1 2 3 > Last ›
EG 2 : ‹ First < 5 6 7 8 9 > Last ›
From the above link how to remove the ">" all arrow mark from the pagination link.
is any keyword set in config parameters.
My code :
public function index()
{
$limit = ($this->uri->segment(4) > 0)?$this->uri->segment(4):0;
$config['base_url'] =base_url().'/dep/index/';
$config["total_rows"] = sizeof($this->MODEL_NAME->COUNT_DEP($companyID, $sortBy, $orderBy));
$config['per_page'] =5;
$config['uri_segment'] = 4;
$config['next_link'] = '';
$config['prev_link'] = '';
$config['num_links'] = 2;
$data["CE"] = $this->MODEL_NAME->get_dep($dep_id, $sortBy, $orderBy,$config["per_page"], $limit);
$data["total_count"] = $config["total_rows"];
$this->pagination->initialize($config);
$data["links"] = $this->pagination->create_links();
$this->load->view('dep/home',$data);
}
You can do with following 4 options:
$config['next_link'] = '';
$config['prev_link'] = '';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
I want your code, but try this
$config['next_link'] = '';
$config['prev_link'] = '';
$config['next_link'] = '<img src="'.base_url().'backend/images/right-arrow.png" >';
$config['prev_link'] = '<img src="'.base_url().'backend/images/left-arrow.png" >';
$config['base_url'] = ''.base_url().'admin/home/userList/?id='.$id.'';
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open']='<li><a href="[removed]void(0);" class="page_active">';
$config['cur_tag_close']='</a></li>';
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;