分页在Codeigniter中不起作用 [英] pagination not working in codeigniter

查看:72
本文介绍了分页在Codeigniter中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器页面

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

    $data['h']="";

   $this->load->library('pagination');
     $config['base_url'] = base_url().'Imagec/index';
    $config['total_rows'] = 10;
    $config['per_page'] = 2;
    $config["uri_segment"] = 4;
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
    $data['h']=$this->Inserts_model->select($config["per_page"], $page);  
    $data["links"] = $this->pagination->create_links();
    $this->load->view('select_view', $data); 

}
我的模式页面

} my mode page

   public function select($limit, $start)  
  {  
     $this->db->limit($limit, $start);
     $query = $this->db->get('student');  
     return $query->result();  
  } 



<我的查看页面

my view page

 <p><?php echo $links; ?></p>

此处所有我的代码都在单击链接时出现未找到的错误

here all my code here when click on links the NOT FOUND error occur's

推荐答案

尝试此100%可以使用

Try this 100% will work

控制器:

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

型号:

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

这篇关于分页在Codeigniter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆