代码点火器

时间:2016-12-08 10:46:01

标签: codeigniter search pagination

我在代码点火器中进行分页,为搜索目的加入两个表

我的模特



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');
}}
&#13;
&#13;
&#13;

这里的问题是分页工作只有一页点击下一个链接显示同一项目这里只显示5个内容只有5个以上的项目但下一页显示相同的元素

1 个答案:

答案 0 :(得分:1)

尝试这样的功能,它肯定会解决您的问题。我再次要求你去阅读文档以获得更多的理解。

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');
    }
}