CodeIgniter分页

时间:2017-02-01 11:50:27

标签: php

我的代码点火器有点麻烦,我今天早上4点工作,我的大脑处于关闭模式。

我有这段代码,

public function books($Page = 0)
    {
        $config['base_url'] = base_url('user/books');
        //Recherche des livres
        $SubSearch = $this->input->post('SubSearch');
        //Nombre occurence par page
        $SubPerPage = $this->input->post('SubPerPage');
        //Configuration du mode d'affichage de tout les livres
            //Gestion du champ de recherche
                if(isset($SubSearch))
                {
                    $this->session->set_userdata('BookSearch',$this->input->post('Search'));
                }
            //Gestion du nombre par page
                if(isset($SubPerPage))
                {
                    $this->session->set_userdata('PerPage',$this->input->post('PerPage'));
                }

            //Gestion nombre affichage per page
            if(!empty($this->session->userdata('PerPage')))
                    {
                        $config['per_page'] = $this->session->userdata('PerPage'); 
                    }else
                    {
                        $config['per_page'] = 10;
                    }
            //La Requette
                if(!empty($this->session->userdata('BookSearch')))
                {
                    $config['total_row'] = $this->functions->getSearch($this->session->userdata('BookSearch'),"","")->num_rows();
                    $query = $this->functions->getSearch($this->session->userdata('BookSearch'),$Page,$config['per_page']);
                }else
                {
                    $config['total_row'] = $this->db->query('SELECT * FROM books')->num_rows();
                    $query = 'SELECT * FROM books LIMIT '.$Page.','.$config['per_page'].'';
                    $query = $this->db->query($query);
                }

                $data['BooksSearchQuery'] = $query->result();
                echo 'perpage : '.$config['per_page'];
                echo 'total row : '.$config['total_row'];
            $this->pagination->initialize($config);

            $this->load->view('user/books',$data);
    }

但是create_links什么都没有,而值

echo 'perpage : '.$config['per_page'];
echo 'total row : '.$config['total_row'];

很好。 一个办法?先谢谢你

2 个答案:

答案 0 :(得分:0)

如果您只有10行而您的配置设置为10则没有要创建的链接。尝试将配置设置为5. $config['per_page'] = 5;

答案 1 :(得分:0)

我解决了我的问题,这是一个愚蠢的错误。

$ Config ['total_row'];

必须是

$ Config ['total_rows'];

真的很蠢!非常感谢你