I'm using codeigniter 3 and using hmvc for admin but problem pagination no showing First a Last link.i could not understand where is the problem
$config['per_page'] = 2;
$config['base_url'] = base_url().'admin/manage-cms';
$config['num_links'] = 20;
$config['uri_segment'] = 3;
$page = $this->uri->segment(3);
$limit_end = ($page * $config['per_page']) - $config['per_page'];
if ($limit_end < 0){
$limit_end = 0;
}
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$data['count_cms']= $this->cms_model->count_cms();
$config['total_rows'] = $data['count_cms'];
$data['cms'] = $this->cms_model->get_cms($config['per_page'],$limit_end);
$this->pagination->initialize($config);
i also updated the code to
$config['per_page'] = 2;
$config['base_url'] = base_url('admin/manage-cms');
$config['num_links'] = 20;
$config['uri_segment'] = 3;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$data['count_cms']= $this->cms_model->count_cms();
$config['total_rows'] = $data['count_cms'];
$data['cms'] = $this->cms_model->get_cms($config['per_page'],$page);
$this->pagination->initialize($config);
But following problem have found
1)in url, pagination coming like url/2,url/4,url/6 etc
But i trying to show url/1,url/2,url/3
2) I have inserted 9 records in db but still First and Last link is not displayed
Related
Cannot access protected property `CI_Pagination
Trying to add submit button on last page of pagination currently it's on every page by default...on line 49 i have condition to check whether i am in last page or not, I want a submit button at the end of the pagination page
Code on which error is showing..please explain how to implement
if($this->pagination->cur_page >= ceil($this->pagination->total_rows / $this->pagination->per_page))
{
$isLastPage = true;
}else{
$isLastPage = false;
}
Pagination code
public function quizdisplay()
{
//echo $this->pagination->create_links();
//$this->load->library('pagination');
$config = array();
$config['base_url'] = 'http://localhost/xampp/cii/index.php/Questions/quizdisplay';
//$config['total_rows'] = 10;
$total_row = $this->quizmodel->record_count();
$config["total_rows"] = $total_row;
$config['per_page'] = 1;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}else{
$page = 1;
}
$data["results"] = $this->quizmodel->getQuestions($config["per_page"], $page);
$this->pagination->create_links();
$data["links"] = $this->pagination->create_links();
View data according to array.
$this->load->view("play_quiz", $data);
}
Both the codes are in same function
Hi have am new to codeigniter and have been struggling with CI pagination library for days.
I have this app where all pagination are working fine except for skipping data by offset.
i.e. when I click on next, It only shifts data by 1 record only. Example: From 1-10 showing it goes to 2-11 and so on..
Here is my controller:
$active = 1;
$total = $this->all_users_model->total_number_of_rows();
$per_page = 10;
$offset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config['base_url'] = base_url().'admin/manage-users/';
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['prev_link'] = 'Previous';
$config['next_link'] = 'Next';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$data['admin_all_users'] = $this->all_users_model->show_all_user_details($active, $per_page, $offset);
Model:
public function show_all_user_details($active,$per_page,$offset) {
$this->db->where(array('activated'=>$active,'admin !='=>1));
$this->db->limit($per_page,$offset);
$this->db->order_by('api_id','desc');
$query=$this->db->get('registered_members');
return $query->result();
}
It's because your offset is incrementing only with one at a time: page/1, page/2, also as your db query limit. Currently, your db limit is $this->db->limit(10, 1);, $this->db->limit(10, 2);.
This shows 10 records from record 1, and then from record 2.
Just change the limit in your model to:
$this->db->limit($per_page, $offset * $per_page);
I want to create a URL containing string from search form and page from pagination
For example, my base URL is example.com/search
When showing the search result it will be example.com/search/?s=keyword and when showing the search result from next page it will be example.com/search/?s=term&p=2 for second page and so on
How to make it like that in CodeIgniter?
try this. here used page instead of p in URL
$keyword = trim($this->input->get('s', TRUE));
$this->load->library('pagination');
$config['total_rows'] = $this->db->get('table_name')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['enable_query_strings'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['query_string_segment'] = 'page';
$config['page_query_string'] = TRUE;
$config['base_url'] = site_url('search/index/?s=' . $keyword);
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
if ($this->input->get('page')) {
$sgm = (int) trim($this->input->get('page'));
$segment = $config['per_page'] * ($sgm - 1);
} else {
$segment = 0;
}
$this->pagination->initialize($config);
// your query
$query = $this->db->select('*')->from('table_name')->limit($config['per_page'], $segment)->get();
now your URL will be same as you mention in your question
$this->load->library('pagination');
$config['base_url'] = base_URL().'admin/issues/list_issues/';
$config['total_rows'] = $this->db->get('dt_issues')->num_rows();
$config['num_links']=10;
$config['per_page'] = 5;
$config['uri_segment'] = 3;
Codeigniter pagination was working properly. But when click on first link it is not working and the remaining links will work. Please help me.
$offset is the variable in which u can get value which page user is reqesting
function list_issues($offset = null)
{
$this->load->library('pagination');
........
// Pagination config
$config['base_url'] = base_URL().'admin/issues/list_issues/';
$config['total_rows'] = $this->provider_model->countprovider();
$config['per_page'] = 3;
// $config['creat_link'] = 1; <-- This is not a valid option
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
// Init config
$this->pagination->initialize($config);
// If the pagination library doesn't recognize the current page add:
$this->pagination->cur_page = $offset;
.....
// further your code
}
I can add pagination, but from page 1 I can't link to page 2. The data on page 2 can't be shown.
My code:
$config['base_url'] = base_url() . 'transaksi/index/';
$config['total_rows'] = 21;
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['first_link'] = 'Awal';
$config['last_link'] = 'Akhir';
$config['next_link'] = 'Selanjutnya';
$config['prev_link'] = 'Sebelumnya';
$this->pagination->initialize($config);
$bc["paginator"] = $this->pagination->create_links();
$this->load->view('transaksidigor/bg_home',$bc);
In autoload:
$autoload['libraries'] = array('database','session','pagination','form_validation','security');
The problem is that you have base_url() which is missing index.php i guess. instead you should always use site_url(). this way either you have set index.php or not it will always send you to the page you are going.
$config['base_url'] = site_url('transaksi/index');
$config['total_rows'] = 21;
$config['per_page'] = 10;
$config['uri_segment'] = 3;
$config['first_link'] = 'Awal';
$config['last_link'] = 'Akhir';
$config['next_link'] = 'Selanjutnya';
$config['prev_link'] = 'Sebelumnya';
$this->pagination->initialize($config);
$bc["paginator"] = $this->pagination->create_links();
$this->load->view('transaksidigor/bg_home',$bc);
Please replace
$config['uri_segment'] = 3; to $config['uri_segment'] = $this->uri->rsegment(3);