1

分页正在工作,但我不知道为什么它每页只显示一个数据?我的数据库中有 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

4

5 回答 5

1

我也面临同样的问题。现在它通过改变这个解决了

$config['uri_segment']
于 2013-08-14T06:26:50.893 回答
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"]定义分页将保存的 url。
您在视图中显示的数据与分页无关。检查您的查询和您获得的偏移量。例如,放在echo $this->db->last_qeury();die;returnfunction getExpenses()语句之前。

于 2013-08-14T06:29:34.327 回答
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;
}
于 2013-08-14T05:45:54.070 回答
1

你需要通过uri segmentlike

$config["uri_segment"] = $last_seg_no;

$last_seg_no将是您可以找到页码的最后一段。并且需要通过per page param也喜欢

$config["per_page"] = 1;//As per your case
于 2013-08-14T05:38:32.317 回答
1

“不知道为什么它每页只显示一个数据??” 因为$config["per_page"] =1;.

添加以下内容,

$config['uri_segment'] = 3; // change based on ur url

将值从 更改$config["per_page"] =1;$config["per_page"] =3;每页显示 3 个数据。

于 2013-08-14T05:38:47.880 回答