pagination not working in codeigniter

前端 未结 1 1035
忘掉有多难
忘掉有多难 2020-12-22 03:07

my controller page

 public function index() {
    $data[\'error\']=\"\";

    $data[\'h\']=\"\";

   $this->load->library(\'pagination\');
     $config         


        
相关标签:
1条回答
  • 2020-12-22 03:39

    Try this 100% will work

    Controller :

    public function index() {
    
        $data['error'] = "";
    
        $data['h'] = "";
    
        $this->load->library('pagination');
    
        $data['h'] = $this->inserts_model->select();
    
        $config['base_url'] = base_url() . '/index.php/imagec/index';
        $config['total_rows'] = count($data['h']);//it will give you total no of records
        $config['per_page'] = 2;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data['h'] = $this->inserts_model->select($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
    //    echo "<pre>";print_r($data);die;
        $this->load->view('select_view', $data);
      }
    

    Model :

    public function select($limit=0, $start=0) {
    
    
        if (empty($start) && !empty($limit)) {
          $this->db->limit($limit);
        }
        if (!empty($start) && !empty($limit)) {
          $this->db->limit($limit, $start);
        }
    
        $query = $this->db->get('student');
        return $query->result();
      }
    
    0 讨论(0)
提交回复
热议问题