如何为以下添加分页

时间:2015-01-29 12:26:59

标签: php codeigniter

如何将分页成功应用于以下代码

code1 :主控制器,我有一个函数login_process检查正在记录的用户是否有效,如果他是有效的,那么检查列中的'状态'是否有效数据库是1或0,如果是1那么他是管理员,他将登录。

    public function login_process()
    {
        $this->load->model('insert_model');
        $data['users'] = array(
                            'fname' => $this->input->post('fname'),

                            'pass'=> $this->input->post('pass'),

                           );           

        $status= $this->insert_model->login_test($data);
        $st['ss']=$this->insert_model->stat($data); 
        //print "<pre>"; print_r($status); die();
        if($status == true )
        {
            if( $st['ss'] [0] ['status'] == 0)
            {
            $ses = array(
                        'username' =>  $this->input->post('fname'),
                        'password' =>  $this->input->post('pass'),
                );

             $this->session->set_userdata($ses);
             $im['pic']=$this->insert_model->image_fetc();

             $this->load->view('header_view',$im);
             $this->load->view('navside_view');
             $this->load->view('user_view');
            }
             else
             {
                $ses = array(
                        'username' =>  $this->input->post('fname'),
                        'password' =>  $this->input->post('pass'),
                );

             $this->session->set_userdata($ses);
             $im['pic']=$this->insert_model->image_fetc();               

            // print_r($aaa); die();
            //  $data['aa'] = "sd"; 

            //$data['books'] = $this->abc();
            $data['books'] = $this->insert_model->pagination();
             //print "<pre>";print_r($data);die();
             $this->load->view('header_view',$im);
             $this->load->view('navside_view');
             $this->load->view('admin_view', $data);
             }
         }
        else
            {

             $this->load->view('header_view');
             $this->load->view('navside_view');
             $this->load->view('center_view_login');
            }

} 

代码2 :现在下一个代码是我的控制器insert_controller代码,其中首先使用各种函数来检查用户是否有效,其次是从数据库检查状态列以及分页代码和图片获取代码。

 public function login_test($users)
    {
        foreach($users as $user)
        {
            $uname = $user['fname'];
            $pass = $user['pass'];
        }
        $query = $this->db->where('fname',$uname)
                ->where('pass',$pass)
                ->get('register');

        if($query->num_rows == 1)    
        {
            return $query->result_array(); 
        }
        else
        {
            return false;
        } 
    }
    public function stat($users)
    {           
        foreach($users as $user)
        {
            $uname = $user['fname'];
            $pass = $user['pass'];
        }
        $s= $this->db->select('status')->where('fname',$uname)->where('pass',$pass)->get('register');
        if($s->num_rows == 1)
        {
            return $s->result_array();
        }
        else
        {
           return false;
        }           
    }
    public function image_fetc()
    {
        $us=$this->session->userdata('username');
        $pass=$this->session->userdata('password');
        $images= $this->db->select('image')->where('fname',$us)->where('pass',$pass)->get('register');
        return $images->result_array();
    }   

public function pagination(){

        //$this->load->model('insert_model');
         //$data ['query'] = $this->insert_model->view_data(); 
        $this->load->library('table');

        // Load Pagination
        $this->load->library('pagination');
        $total_row = $this->db->count_all("register");
        // Config setup
        $config['base_url'] = base_url().'index.php/welcome/login_process';
        $config['total_rows'] = $total_row;
        $kk=$config['use_page_numbers'] = TRUE;
        $config['per_page'] = 2;
        // I added this extra one to control the number of links to show up at each page.
        $rpp = $config['num_links'] = 5;

        // Initialize
        $this->pagination->initialize($config);

        // Query the database and get results
        // Here we add the limit and the offset
        // The second parameter is the limit, since we are showing
        // 10 per page, the limit should be 10

        if($this->uri->segment(3)){
            $page = ($this->uri->segment(3)) ;
            }
            else{
            $page = 1;
            }
        $offset = ($rpp*$page)-$rpp;
        $qry = $this->db->get('register',15, $offset);

        // Create custom headers
        $header = array('id','username','lastname','email' , 'password', 'image','status');
        // Set the headings
        $this->table->set_heading($header);
        // Load the view and send the results
       // print_r($offset);die();
     /*   if($offset == 0)
        {   

        return $data['books'];

        }
        else
        {
       //$data['books'] = $this->abc();
            $im['pic']=$this->insert_model->image_fetc();
        $this->load->view('header_view',$im);
         $this->load->view('navside_view');
           $this->load->view('admin_view', $data);
            }
       // print_r($data); die();

    }*/return $qry->result_array();

}}

code3 :最后一段代码是我的admin_view的代码,我想在其中成功进行分页,但是它没有正常运行所以plz帮助我如何使用这整个代码正确地进行分页

<?php echo $this->table->generate($books); ?>
<?php echo $this->pagination->create_links(); ?>

PLZ帮助我,我错了,并且正确无误

0 个答案:

没有答案