duanpu1111 2017-02-01 11:50
浏览 32

CodeIgniter分页

I have a little trouble with code igniter, I work since 4h this morning, my brain is in off mode.

I have this code,

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);
    }

But the create_links gives nothing, while the values

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

are good. A solution? thank you by advance

  • 写回答

2条回答 默认 最新

  • douke1942 2017-02-01 15:35
    关注

    If you have only 10 rows and your config is set to 10 then there are no links to create. Try setting the config to 5. $config['per_page'] = 5;

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀