【发布时间】:2014-02-14 02:47:05
【问题描述】:
大家好,我正在尝试使用 codeigniter 分页显示 mysql 数据库记录..为此我编写了以下代码..当我运行它时,它在一页中显示所有结果,而页码显示正确根据给定的每页限制..
型号:
function get_records($user_name, $limit, $start) {
$this->db->limit($limit, $start);
$this->db->select('GROUP_CONCAT(cid) AS cIDs');
$this->db->where('user_name', $user_name);
$this->db->group_by("company_user");
$this->db->from('company_records');
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
function count_records($user_name) {
$this->db->select('GROUP_CONCAT(cid) AS cIDs');
$this->db->where('user_name', $user_name);
$this->db->group_by("company_user");
return $this->db->count_all('company_records');
}
控制器:
$this->load->model('Records', 'Records', TRUE);
$this->load->library('pagination');
$config['base_url'] = base_url() . 'records/index';
$config['total_rows'] = $this->Records->count_records($this->session->userdata('user'));
$config['per_page'] = 10;
$config["uri_segment"] = 4;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
/* $start = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; */
if ($this->uri->segment(4) > 0) {
$offset = ($this->uri->segment(4) + 0) * $config['per_page'] - $config['per_page'];
} else {
$offset = $this->uri->segment(4);
}
$data['recordsDetails'] = $this->Records->get_records($this->session->userdata('user'), $config["per_page"], $offset);
$data['pages'] = $this->pagination->create_links();
我已经尝试过谷歌搜索和stackoverflow..但还没有找到任何解决方案..可能是我的查询有问题或者我不知道..
请帮帮我...
【问题讨论】:
-
你的 count_records 似乎不对
-
先生,您能建议我如何计算...
-
我已经从
$config['total_rows'] = $this->Records->count_records($this->session->userdata('user'));尝试过$config['total_rows'] = 15但这又不起作用 -
uri_segment 是否正确?
-
http://localhost/company/records这是我的网址..
标签: php mysql codeigniter pagination