代码点火器中的分页 [英] Pagination in code igniter
本文介绍了代码点火器中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在代码点火器中进行分页,出于搜索目的将两个表连接起来
I am do pagination in code igniter ,join two tables for Search purpose
我的模特的
public function main_search_count($term)
{
if ($term == "NIL") $term = "";
$this->db->select('*');
$this->db->from('tbl_doctor');
$this->db->join("tbl_specialisation", "tbl_specialisation.spec_id = tbl_doctor.spec_id",'left');
$this->db->where("(tbl_doctor.dr_name LIKE '%".$term."%' OR tbl_doctor.district LIKE '%".$term."%' OR tbl_specialisation.spec_specialise LIKE '%".$term."%')");
$query= $this->db->get();
return $query->num_rows();
}
public function fetch_data($limit, $offset, $term)
{
if ($term == "NIL") $term = "";
$this->db->select('*');
$this->db->from('tbl_doctor');
$this->db->join("tbl_specialisation", "tbl_specialisation.spec_id = tbl_doctor.spec_id",'left');
$this->db->where("(tbl_doctor.dr_name LIKE '%".$term."%' OR tbl_doctor.district LIKE '%".$term."%' OR tbl_specialisation.spec_specialise LIKE '%".$term."%')");
$this->db->limit($limit, $offset);
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query;
}
}
我的控制器
function get_quick_doct($offset = 0)
{
$term = ($this->input->post("term"))? $this->input->post("term") : "NIL";
$term = ($this->uri->segment(3)) ? $this->uri->segment(3) : $term;
$config = array();
$config["base_url"] = base_url() . "User/get_quick_doct/$term";
$config['total_rows'] = $this->Search_model->main_search_count($term);
$config['per_page'] = 5;
$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'] = 'Prev';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$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);
$data['quick_doc'] = $this->Search_model->fetch_data($config['per_page'], $offset,$term);
$data['get_specs'] = $this->specialisation_model->get_specialisation();
$data['get_specs'] = $this->specialisation_model->specialisation_get();
if($data){
$this->load->helper(array('form', 'url'));
$this->load->view('customer/header', $data);
$this->load->view('customer/side_view',$data);
$this->load->view('customer/quick_search',$data);
$this->load->view('customer/footer');
}
else{
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">No sdfdsfds Results available for your search!!!</div>');
$this->load->view('customer/header', $data);
$this->load->view('customer/side_view',$data);
$this->load->view('customer/main_search');
$this->load->view('customer/footer');
}}
这里的问题是分页工作仅一页单击下一个链接在此处显示相同的项目仅显示5个内容,总共仅超过5个项目,但是下一页显示相同的元素
here the problem is the pagination work only one page click next link show same item here show only 5 content only totally more than 5 item but next page show same element
推荐答案
尝试这样的功能,它肯定会解决您的问题.再次,我要求您获取文档以进一步了解.
Try the function like this, it will definitely solve your problem. Again I am requesting you to go for the documentation for more understanding.
function get_quick_doct()
{
$term = ($this->input->post("term"))? $this->input->post("term") : "";
$config = array();
$config["base_url"] = base_url() . "User/get_quick_doct/";
$config['total_rows'] = $this->Search_model->main_search_count($term);
$config['per_page'] = 5;
$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'] = 'Prev';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next';
$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);
$segment = $this->uri->segment (2); // 2 or 3 -- as per your url depth
$data['quick_doc'] = $this->Search_model->fetch_data($config['per_page'], $segment, $term);
$data['get_specs'] = $this->specialisation_model->get_specialisation();
$data['get_specs'] = $this->specialisation_model->specialisation_get();
if($data)
{
$this->load->helper(array('form', 'url'));
$this->load->view('customer/header', $data);
$this->load->view('customer/side_view',$data);
$this->load->view('customer/quick_search',$data);
$this->load->view('customer/footer');
}
else{
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">No sdfdsfds Results available for your search!!!</div>');
$this->load->view('customer/header', $data);
$this->load->view('customer/side_view',$data);
$this->load->view('customer/main_search');
$this->load->view('customer/footer');
}
}
这篇关于代码点火器中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文