搜索结果中的Codeigniter分页

时间:2016-12-31 20:26:55

标签: php codeigniter pagination

我已经在我的网站上完成了我的搜索功能编码,但它没有分页。所以现在,我试图实现它的分页,但似乎有一个问题。通过对我的搜索查询使用isset,我将无法加载页面中的两个页面,因为查询将始终为false。如何在搜索功能中正确实现分页?

控制器:

    function search_homeowner()
    {
         $this->load->model('model_accounts');
         $searchquery = $this->input->post('search');

         if(isset($searchquery) and !empty($searchquery))
         {
            $query =   $this->db->select('*')->from('accounts')->where('(role = 0 AND isActive = 1)',NULL,FALSE)->where('(CONCAT(firstname," ",lastname) LIKE "%'.$searchquery .'%" OR firstname LIKE "%'.$searchquery .'%" OR lastname LIKE "%'.$searchquery .'%" OR username LIKE "%'.$searchquery .'%" OR address LIKE "%'.$searchquery .'%" )',NULL,FALSE)->get();
            $config['base_url'] = site_url('admin_accounts/search_homeowner');
            $config['total_rows'] = $query->num_rows();
            $config['per_page'] =  15;
            $config_deact['num_links'] = 5;
            $config['use_page_numbers'] = TRUE;
            $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>";
            $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['homeownerlinks'] = $this->pagination->create_links();

            $data['users'] = $this->model_accounts->search_homeowner($searchquery, $config['per_page'], $this->uri->segment(3));
            $data['main_content'] = 'view_adminaccounts';

            $this->load->view('includes/admin_accounts_template', $data);
         }
         else
        {
            redirect('admin_accounts/homeowner');
        }
     }

型号:

function search_admin($searchquery)
{
  $this->db->select('*')->from('accounts');
  $this->db->where('(role = 1 AND isActive = 1)',NULL,FALSE);
  $this->db->where('(CONCAT(firstname," ",lastname) LIKE "%'.$searchquery .'%" OR firstname LIKE "%'.$searchquery .'%" OR lastname LIKE "%'.$searchquery .'%" OR username LIKE "%'.$searchquery .'%" OR address LIKE "%'.$searchquery .'%" )',NULL,FALSE);
  $query = $this->db->get();

    if($query->num_rows() > 0)
    {
        return $query->result();
    }
    else
    {
        return $query->result();
    }

}

0 个答案:

没有答案