如何使用数据库Codeigniter对类别进行分页

时间:2017-08-25 16:58:32

标签: php codeigniter codeigniter-3

大家好我是codeigniter的新手我在codeigniter上有分页问题(网址类别)我试着搜索google和youtube但是我不能做谁能帮助我

这是我的代码模型:

这是我的控制器Category.php

public function category_product_get($id){
    $this->load->library('pagination');
    $config['page_query_string'] = TRUE;
    $config['query_string_segment'] = 'offset';

    $config['base_url'] = 
    base_url().'coustomer/category/category_product_get/'.$id;


    $config['total_rows'] = $this->HomeCat_MOdel->get_books_count($id);
    $config['per_page'] = "1";
    $config["uri_segment"] = 4;
    $choice = $config["total_rows"]/$config["per_page"];
    $config["num_links"] = floor($choice);

    // integrate bootstrap pagination
    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['first_link'] = false;
    $config['last_link'] = false;
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['prev_link'] = '«';
    $config['prev_tag_open'] = '<li class="prev">';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '»';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $this->pagination->initialize($config);

    $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    // get books list
    $data['booklist'] = $this->HomeCat_MOdel->get_books($config["per_page"], 
    $data['page'], $id);

    $data['pagination'] = $this->pagination->create_links();


    $data['Header']             =   'header';
    $data['CategoryPro']        =   'category_product';
    $data['Footer']             =   'footer';
    $data['MainCat']    = $this->Category_model->get_data('category');
    $data['SubCat']     = $this->Category_model->get_data('subcategory');
    $data['Sub_SubCat'] = $this->Category_model-**strong text**>get_data('sub_subcategory');

    // load view
    $this->load->view('home',$data);
}

这是我的模型HomeCat_Model.php

function get_books($limit, $start,$id, $st = NULL)
{
    $this->db->where('product_category_name',$id);
    $records=$this->db->get('products', $limit, $start)->result();
    return $records;
}

function get_books_count($id = NULL)
{

    $this->db->select('*');
    $this->db->where('product_category_name',$id);
    $query = $this->db->get('products');
    $num = $query->num_rows();

    return $num;
}

0 个答案:

没有答案