如何添加页面?

时间:2022-06-29 10:17:43

Using CodeIgniter 2.0.2

使用CodeIgniter 2.0.2

I want to set up pagination for my website.

我想为我的网站设置分页。

This is what I've in my controller:

这就是我在我的控制器中的内容:

$config = array();
$config["base_url"] = base_url() . "/credits";
$config['total_rows'] = 200;
$config['per_page'] = 2; 
$config["uri_segment"] = 3;

$this->pagination->initialize($config);

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->credits_model->fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();

Model:

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

public function fetch_countries($limit, $start) {
    $this->db->limit($limit, $start);
    $query = $this->db->get("sadmin_credits");

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;
}

I need some help in getting it to work. It shows the numbers but when I click on them it just shows the same results nothing changes.

让它发挥作用我需要一些帮助。它显示了数字,但是当我点击它们时,它只显示相同的结果,没有任何变化。

1 个解决方案

#1


0  

try this

public function credits($offset='')
{
    $total_rows = $this->credits_model->record_count();
    $config['base_url'] = base_url() . "/credits";
    $config['total_rows'] = $total_rows;
    $config['per_page'] = 2; 

    $this->pagination->cur_page = $offset;
    $this->pagination->initialize($config);  
    $data["results"] = $this->credits_model->fetch_countries($config["per_page"], $offset);
    $data["links"] = $this->pagination->create_links();
}

or check this tutorials

或者查看本教程

http://only4ututorials.blogspot.in/2014/04/pagination-with-codeigniter.html

#1


0  

try this

public function credits($offset='')
{
    $total_rows = $this->credits_model->record_count();
    $config['base_url'] = base_url() . "/credits";
    $config['total_rows'] = $total_rows;
    $config['per_page'] = 2; 

    $this->pagination->cur_page = $offset;
    $this->pagination->initialize($config);  
    $data["results"] = $this->credits_model->fetch_countries($config["per_page"], $offset);
    $data["links"] = $this->pagination->create_links();
}

or check this tutorials

或者查看本教程

http://only4ututorials.blogspot.in/2014/04/pagination-with-codeigniter.html