【问题标题】:codeigniter pagination: links are working but the records are repeated on other pagescodeigniter 分页:链接正常,但记录在其他页面上重复
【发布时间】:2018-05-28 11:06:51
【问题描述】:

谁能帮帮我?我正在尝试对我的表格进行分页。所有链接都有效,但这些项目在其他页面上重复。我在这里尝试了类似的问题,但没有任何效果。

function index($type="deposit", $limit_from=0)
{
    $limit_from = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
    $total_records = $this->Expense->get_total_rows($type);
    $data['controller_name'] = $this->get_controller_name();

    $lines_per_page = 3; 
    $data[$type.'s'] = $this->Expense->get_records($lines_per_page, $limit_from, $type);

    $config['base_url'] = base_url('index.php/expenses/index/'.$type);
    $config['total_rows'] = $total_records;
    $config['per_page'] = 3;
    $config["uri_segment"] = 4;
    // $choice = $total_records / $config['per_page'];
    // $config['num_links'] = round($choice);
    $config['use_page_numbers'] = TRUE;
    $config['first_url'] = base_url('index.php/expenses/index/'.$type.'/1');

    $this->pagination->initialize($config);
    $data["links"] = $this->pagination->create_links();

    $this->load->view('expenses/'.$type, $data);
    $this->_remove_duplicate_cookies();
}

【问题讨论】:

标签: codeigniter pagination


【解决方案1】:

谢谢大家。我得到了它的工作:下面是我最终做的,它工作得很好!

function index($type="deposit", $sort_by='deposit_date', $sort_order='asc', $page_limit=0)

{
    $data['controller_name'] = $this->get_controller_name();
    $config = array();
    $config['base_url'] = site_url("expenses/index/$type/$sort_by/$sort_order");
    $config['total_rows'] = $this->Expense->get_total_rows($type);
    $config['per_page'] = 4;
    $config["uri_segment"] = 6;

    $data['num_rows'] = $config['total_rows'];
    $data['type'] = $type;


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

    $page = ($this->uri->segment(6)) ? $this->uri->segment(6) : 0;

    $data[$type.'s'] = $this->Expense->get_records($config["per_page"], $page, $type, $sort_by, $sort_order);
    $data["links"] = $this->pagination->create_links();

    $data['headers'] = $this->Expense->table_headers($type);
    $data['sort_by'] = $sort_by;
    $data['sort_order'] = $sort_order;


    $this->load->view('expenses/'.$type, $data);
    $this->_remove_duplicate_cookies();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 2016-10-21
    • 2020-08-30
    • 1970-01-01
    • 2018-06-11
    • 2019-08-01
    • 1970-01-01
    相关资源
    最近更新 更多