0

嗨,我正在尝试使用代码点火器正确分页,但似乎它不想正常工作。我得到了第二页,但分页消失了,但我仍然得到了正确的表格,但我有 2 个错误:

A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: models/evaluation_model.php
Line Number: 37

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/evaluation_model.php
Line Number: 37

控制器功能:

function showEvaluations($offset = 0)
        {
            if($this->login->is_logged_in())
            {
                $limit = 5;
                $result = $this->evaluation_model->getAllEvaluations($limit, $offset);

                if ($this->session->userdata('type') == 'admin')
                {
                    $data['evaluations'] = $result['evaluations'];
                    $data['total'] = $result['num_rows'];
                    $data['notallowed'] = false;
                    $config = array();
                    $config['base_url'] = base_url("evaluation/showEvaluations/");
                    $config['total_rows'] = $data['total'];
                    $config['per_page'] = $limit;
                    $config['uri_segment'] = 3;
                    $this->pagination->initialize($config);
                    $data['pagination'] = $this->pagination->create_links();
                    $this->load->view('allevaluations_view',  $data);
                }
                else
                {
                    $data['notallowed'] = true;
                    $this->load->view('allevaluations_view',  $data);
                }


                //$this->load->view('allevaluations_view',  $data);
            }
            else
            {
                $this->load->view('login_view');
            }
        }

和模型:

function getAllEvaluations($limit, $offset)
        {
            $q = $this->db->select('tblPunten.PK_PuntID, tblPunten.Titel, tblPunten.Score, tblVakken.Vak, tblUsers.username, tblUsers.Voornaam, tblUsers.Achternaam')
                          ->from('tblPunten')
                          ->join('tblVakken', 'tblPunten.FK_VakID = tblVakken.PK_VakID')
                          ->join('tblUsers', 'tblPunten.FK_UserID = tblUsers.PK_UserID')
                          ->limit($limit, $offset);

            $query['evaluations'] = $q->get()->result();

            $q = $this->db->select('COUNT(*) as count', FALSE)
                          ->from('tblPunten')
                          ->limit($limit, $offset);
             $tmp = $q->get()->result();
             $query['num_rows'] = $tmp[0]->count;
             return $query;


        }

第 37 行: $query['num_rows'] = $tmp[0]->count;

4

2 回答 2

1

找到了,第二个查询:

$q = $this->db->select('COUNT(*) as count', FALSE)
                          ->from('tblPunten')
                          ->limit($limit, $offset);

必须无限制:

$q = $this->db->select('COUNT(*) as count', FALSE)
                      ->from('tblPunten')
于 2012-08-29T19:02:49.233 回答
0

在 codeigniter 中,->result()一个对象。

如果你想要那种形式的数组,那么我们可以使用->result_array()这样我们就可以得到数组形式的结果集。

$tmp = $q->get()->result_array();//made changes
$query['num_rows'] = $tmp[0]['count'];//will work
于 2012-08-30T05:44:39.280 回答