duanjiani6826 2015-02-25 17:44
浏览 53
已采纳

codeigniter分页页码问题

I'm trying to use Codeigniter pagination library , i want my pagination url to be like this :

mysite.com/codeigniter/controller/page/1

mysite.com/codeigniter/controller/page/2

mysite.com/codeigniter/controller/page/3

here is my controller :

class Controller extends CI_Controller {
    public function index() {
        $this->load->model('model');
        $segment=$this->uri->segment(3);
        /* Pagination */
        $config['base_url']=base_url('controller/index');
        $config['total_rows']=$this->model->count_active_members()->num_rows;
        $config['per_page']=5;
        $config['uri_segment'] = 3;
        $config['use_page_numbers'] = TRUE;
        $this->pagination->initialize($config);
        /* END Pagination */
        $result['members']=$this->model->get_active_members($segment);
        $this->load->view('view',$result);
    }
}

my model :

class Model extends CI_Model {
    public function get_active_members($segment) {
        $this->db->select('username,email,balance,ctimes,regdate');
        $this->db->limit(5,$segment);
        return $this->db->get_where('members',array('status'=>'active'));
    }

    public function count_active_members() {
        return $this->db->get_where('members',array('status'=>'active'));
    }   
}

it worked as i want but the problem that i have 9 rows in my db & it displays only 7

  • 写回答

1条回答 默认 最新

  • dongniuxia8650 2015-02-25 18:01
    关注

    I think your problem is the offset, try this instead :

    $this->db->select('username,email,balance,ctimes,regdate');
    $per_page = 5;
    $segment = $segment > 0 ? (($segment - 1) * $per_page) : $segment;
    $this->db->limit($per_page, $segment);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化