“Displaying X to Y of Z results” using Codeigniter pagination library?

前端 未结 3 1884
名媛妹妹
名媛妹妹 2021-01-15 05:58

I am, using the Codeigniter pagination library,

I am wondering how I can grab the number of the first and last items displayed using the pagination class?

So

3条回答
  •  感情败类
    2021-01-15 06:32

    In CodeIgniter Controller file

    $params['limit'] = 15; $params['offset'] = ($this->input->get('per_page')) ? $this->input->get('per_page') : 0;

        $config = $this->config->item('pagination');
        $config['per_page'] = $params['limit'];
        $config['base_url'] = site_url('cy_controller/action?');
    
        $config['total_rows'] = $this->abcd_model->get_count($params);
        $this->pagination->initialize($config);
        $data['merchant'] = $this->abcd_model->get_all($params);
        $countMerchant = count($data['merchant']);
        if ($params['offset'] == 0) {
            $find_total_record = $countMerchant;
        } else {
            $valuec = $params['offset'] + $params['limit'];
            if ($valuec > $config['total_rows'])
                $find_total_record = $params['offset'] + $countMerchant;
            else
                $find_total_record = $params['offset'] + $params['limit'];
        }
        $per_page_total = $find_total_record;
    
        $initial = $params['offset'] == 0 ? 1 : $params['offset'];
        $data['showing'] = "Showing  " . $initial . " to " . $per_page_total . " of " . $config['total_rows'] . " results";
    
    
        $data['_view'] = 'cy_controller/action';
        $this->load->view('layouts/main', $data);
    

    And in view file

     

提交回复
热议问题