分页正在运行,但我不知道为什么它每页只显示一个数据?而且我的数据库中有20个数据,我只能看到6个数据中的6个数据:(
这是我的控制器
function view($page=0){
$config = array();
$config["base_url"] = base_url() . "index.php/view_expenses/view";
$config["total_rows"] = $this->emp_expenses_model->getTotalExpensesCount();
$config["per_page"] =1;
$this->pagination->initialize($config);
$this->data["results"] = $this->emp_expenses_model->getExpenses($config["per_page"], $page);
$this->data["links"] = $this->pagination->create_links();
$this->data['title'] = 'Payroll System';
$this->data['message'] = $this->session->flashdata('message');
$this->load->view('view_expenses', $this->data);
}
这是我的模特
function getTotalExpensesCount() {
return $this->db->count_all("emp_expenses");
}
function getExpenses($limit, $start) {
$this->db->limit($limit, $start);
$qry= $this->db->get("emp_expenses");
return $qry->result();
}
提前感谢任何帮助:D
答案 0 :(得分:1)
您需要传递uri segment
之类的
$config["uri_segment"] = $last_seg_no;
此处$last_seg_no
将是您可以找到页码的最后一段。还需要传递per page param
,如
$config["per_page"] = 1;//As per your case
答案 1 :(得分:1)
“不知道为什么每页只显示一个数据?”因为$config["per_page"] =1;
。
添加以下内容,
$config['uri_segment'] = 3; // change based on ur url
将值从$config["per_page"] =1;
更改为$config["per_page"] =3;
,以便每页显示3个数据。
答案 2 :(得分:1)
试试这个
$config['uri_segment'] = 3;
$config["per_page"] = 3;
像这样修改模态函数
function getTotalExpensesCount() {
$this->db->select("count(*) as CNT");
$qry = $this->db->get("emp_expenses");
$result2 = $qry->row()->CNT;
return $result2;
}
答案 3 :(得分:1)
我遇到了同样的问题。现在它通过改变这个来解决了
$config['uri_segment']
答案 4 :(得分:1)
试试这个:
function view(){
$config = array();
$config["base_url"] = base_url() . "index.php/view_expenses/view/".$this->uri->segment(3);
$config["total_rows"] = $this->emp_expenses_model->getTotalExpensesCount();
$config["per_page"] = 5;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$this->data["results"] = $this->emp_expenses_model->getExpenses($config["per_page"], $this->uri->segment(3));
$this->data["links"] = $this->pagination->create_links();
$this->data['title'] = 'Payroll System';
$this->data['message'] = $this->session->flashdata('message');
$this->load->view('view_expenses', $this->data);
}
function getExpenses($limit, $start = 0) {
$qry= $this->db->get("emp_expenses", $limit, $start);
return $qry->result();
}
$config["per_page"] = 5;
表示您希望每页显示5个数据,$config['uri_segment'] = 3;
表示哪个细分受众群将保留您在查询中使用的偏移量。 $config["total_rows"]
定义总数。表中的行数。 $config["base_url"]
定义了分页所包含的网址
您在视图中显示的数据与分页无关。检查您的查询和您获得的偏移量。例如。在返回声明之前将echo $this->db->last_qeury();die;
放在function getExpenses()
中。