Error in pagination of codeigniter 1

前端 未结 3 1120
鱼传尺愫
鱼传尺愫 2021-01-25 07:33

In model/rci_model.php

public function record_count() {
return $this->db->count_all(\"produk\");
}

public function fetch_countries($limit, $start) {
    $         


        
相关标签:
3条回答
  • 2021-01-25 08:12

    Try This

    in cotroller

    $count = $this->rci_model->get_count(); //get number of rows
    
    $config['base_url'] = base_url().'index.php/sandal_clarudo/sandals_for_men/';
    $config['total_rows'] = $count;
    $config['per_page'] = 5;
    $config['uri_segment'] = 3;
    $limit = $config['per_page'];
    
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    
    $data['links'] = $this->pagination->create_links();
    
    $data["results"] = $this->rci_model->fetch_countries($limit, $page);
    

    in model

    public function get_count() 
    {
      //count          
    $query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men'");
    $result = $query->result_array();
    $count = count($result);
     return $count;
    }
    //data from table
    public function fetch_countries($limit, $page) 
    {
    $query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men' LIMIT $page, $limit");
    $result = $query->result_array();
    return $result;
    }
    

    in view

    //to show data
    <?php
    foreach ($results as $new_result)
    {
    echo $new_result['nama_podak'];
    }
    ?>
    
    //to show pagination
    <?php
    echo $link//Page segment tabs(you can config boostarp for this)
    ?>
    
    0 讨论(0)
  • 2021-01-25 08:16
    $this->db->limit($limit, $start);
    $this->db->where('id_kategori', 'men');
    $this->db->order_by('nama_produk');
    $query = $this->db->get("produk");
    

    Hope this work!

    for count use :

    public function record_count($limit, $start) {
                $this->db->from('count(id_produk) AS count');
                $this->db->where('id_kategori', 'men');
                $this->db->order_by('nama_produk');
                $this->db->limit($limit, $start);
                $return = $query->row_array();
                return $return['count'];
            }
    
    0 讨论(0)
  • 2021-01-25 08:27

    Try this one. You wrong when using limit.

    $query=$this->db->query("SELECT * FROM produk WHERE id_kategori='Men' order by nama_produk ASC LIMIT $limit, $start");
    
    0 讨论(0)
提交回复
热议问题