【问题标题】:Table rows not correctly working with pagination in codeigniter表格行无法正确使用 codeigniter 中的分页
【发布时间】:2018-08-23 15:44:18
【问题描述】:

我正在为我的表格使用分页。我想一次显示 5 行。我的桌子上有 10 件物品。所以这意味着分页应该显示1和2。它确实显示1和2。我的问题是当它在分页中为1时,表显示前5条记录(1到5),如果我在分页表中单击2应该显示6到10条记录放。但在我的情况下,它显示了 3 到 7 条记录。

控制器...

function index(){

    $data['villages'] = $this->m->getVote();
    $this->load->view('index',$data);

}

function index1(){
    $this->load->library('pagination');
    $config['base_url']=base_url().'homecon/index1';
    $config['uri_segment'] = 3;
    $config['per_page'] = 5;

    $page = $this->uri->segment(3,0);

    $data['villages'] = $this->m->getVote($config['per_page'],$page);
    $config['total_rows'] = $this->m->getTotalRow();
    $this->pagination->initialize($config);
    $data['pagination'] = $this->pagination->create_links();
    $this->load->view('index1',$data);

}

型号...

private $lastQuery ='';

public function getVote($limit,$start){
    $this->db->order_by('voter_id','ASC');
    $this->db->limit($limit,$start);
    $query=$this->db->get('voter_details');
    $this->lastQuery = $this->db->last_query();
    if($query->num_rows()>0){
        return $query->result();
    }else{
        return false;
    }


}
public function getTotalRow(){
        $sql =explode('LIMIT', $this->lastQuery);
        $query = $this->db->query($sql[0]);
        $result = $query->result();
        return count($result);
    }

Pagination 1

Pagination 2

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    您将页面传递给模型,而不是开始索引。

    试试这个

    $data['villages'] = $this->m->getVote($config['per_page'], $page*$config['per_page']);
    

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多