【问题标题】:Codeigniter pagination does not display dataCodeigniter 分页不显示数据
【发布时间】:2018-02-22 09:34:02
【问题描述】:

我正在使用codeigniter分页,它根据passingID显示,第一页只显示链接但没有数据

我的控制器:

public function searchpagenat($hsp)

$config = array();
$config["base_url"] = base_url() . "User/searchpagenat/";
$config['total_rows'] = $this->Doctor_model->get_doc_by_hospital($hsp);
$config['per_page'] = 4;
$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 (3);
$data['serv'] = $this->Doctor_model->get_doc_by_hsp($config['per_page'], $segment,$hsp);

和模型

public function get_doc_by_hospital($hsp)  
{ 
$this->db->select('*');  
$this->db->from('tbl_doctor');
$this->db->where('hosp_id',$hsp);
$query = $this->db->get();
return $query->num_rows();
}
public function get_doc_by_hsp($limit, $offset, $hsp)
{
$this->db->select('*');    
$this->db->from('tbl_doctor'); 
$this->db->where('hosp_id',$hsp);
$this->db->limit($limit, $offset);
$query= $this->db->get();  
if($query->num_rows()>0)
{
return $query;
} 

这里的查询正在工作,问题是传递的 id 分页链接在传递 id 的基础上工作,传递的 id 大于 count 显示没有数据。

它是如何解决的?有什么办法吗?请帮帮我?

【问题讨论】:

  • 你加载分页库了吗?
  • 你添加了这个吗? { $data['links'] = $this->pagination->create_links(); }
  • 在 get_doc_by_hsp($limit, $offset, $hsp) 中使用 { return $query->result(); }
  • @DanishAli 是的,我会加载它会工作,problelm 传递的 id 大于 count 没有数据显示

标签: php codeigniter pagination


【解决方案1】:

更改分页代码,如

$config['per_page'] = 4;
    $config["uri_segment"] = 4;
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
    $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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2017-12-01
    • 1970-01-01
    • 2021-02-17
    • 2019-02-08
    相关资源
    最近更新 更多