2012-04-13 104 views
0

我控制器分页的笨工作不正常

function index() 
{ 
    $this->load->library('pagination'); 
    $this->load->model('specialoffer_model'); 
    if($this->input->post('btnUpdate')) 
    { 
     $this->specialoffer_model->addoffer(); 
    } 
    $data['addoffer']=$this->specialoffer_model->addoffer(); 
    $data1=array(
       'row'=>$data['addoffer']['row'], 
       'result'=>$data['addoffer']['result'], 
       ); 
    $config['base_url'] = site_url('specialoffer/index') . '/'; 
    $config['total_rows'] = $this->db->count_all('home'); 
    $config['per_page'] =2; 
    $this->pagination->initialize($config); 
    $data1['results'] = 
        $this->specialoffer_model->get_page (
           $config['per_page'], 
           $this->uri->segment(3)); 
    $this->load->view('specialoffer',$data1); 
} 

视图

echo $this->pagination->create_links(); 

只有页面链接生成,并在其点击页面刷新,但所有从表中记录显示,而我从表中指定2条记录显示。简而言之,分页不起作用。帮助

+0

任何建议或意见,请迫切 – asifa 2012-04-13 06:24:07

+0

请发表您的型号代码,我敢肯定你没有使用偏移量和限制条款在查询 – 2012-04-13 07:46:44

+0

功能get_page( $ num,$ offset) { \t $ query = $ this-> db-> get('home',$ num,$ offset); \t return $ query; } – asifa 2012-04-13 08:51:37

回答

0

其更好地使用:

$this->db->limit($num,$offset); 
$query = $this->db->get('home'); 
return $query->row_array();