Codeigniter:分页不会出现

时间:2015-12-16 07:42:57

标签: codeigniter search pagination

首先,我是Codeigniter的新手。

我在显示分页链接时遇到问题。但是当我使用搜索时,分页显示出来。然后弹出另一个问题,当我搜索时会有分页链接,当我点击链接时它没有显示分页搜索但显示整个非搜索结果。

控制器:

    public function info($offset=0)
{       

    $this->load->library('pagination');

    $count = $this->ticketing_mdl->count_all_ticket();




    $limit = 4;

    $config['base_url'] = "/ticketing/index.php/ticketing/info";
    $config['total_rows'] = $count;
    $config['per_page'] = $limit;

    $config['num_links'] = $limit;
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['pagination'] = $this->pagination->create_links();

    $data['ticket_list'] = $this->ticketing_mdl->get_all_ticket($limit, $offset);

    $this->load->view('ticketing/header');
    $this->load->view('ticketing/left_menu');
    $this->load->view('ticketing/info',$data);
}

型号:

function get_all_ticket($limit,$page)
{


    if($this->input->get('search')){
        $match = $this->input->get("search");
         $sql = "SELECT * FROM db_ticketing.tr_ticket WHERE requested_by LIKE '%$match%' limit $page,$limit";
        return $this->db->query($sql);
    }else{
    $match = $this->input->get("search");
    //$sql = "SELECT * FROM db_contract.bs_contract WHERE contract_tag LIKE '%$match%'";
     $sql = "SELECT * FROM db_ticketing.tr_ticket  limit $page";
    return $this->db->query($sql);
    }
}

2 个答案:

答案 0 :(得分:0)

变化: return $this->db->query($sql);return $this->db->query($sql)->result(); 希望这有帮助!

答案 1 :(得分:0)

修复了显示分页的第一个问题。现在问题是当我搜索关键字时,分页显示出来。但是当我点击分页链接时,它不会继续搜索结果分页

控制器

if($this->input->get('search')){
    $count = $this->ticketing_mdl->count_all_ticket();
    $config['total_rows'] = $count;
    }else{
    $this->db->where('is_valid','1');
    $config['total_rows'] = $this->db->count_all_results('db_ticketing.tr_ticket');

    }