我在桌子上使用分页。我想一次显示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);
}
答案 0 :(得分:0)
您正在将页面传递给模型,而不是起始索引。
尝试一下
$data['villages'] = $this->m->getVote($config['per_page'], $page*$config['per_page']);