Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

pagination not working in codeigniter

my controller page

 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...