【问题标题】:pagination limit and offset is not working in codeigniter分页限制和偏移在 codeigniter 中不起作用
【发布时间】:2017-05-03 13:31:32
【问题描述】:

我想在代码点火器中创建分页。一切正常,但 $limit 和 $id 不起作用,这就是为什么我的视图不会转到下一页。我尝试了更多方法,但没有达到我的目标。请任何人帮忙。

型号

public function display_testSuiteRun($limit, $id) {
    $sql = "
        SELECT tsr.id as id, tsr.name as name, ts.test_suite_name as test_suite_name, GROUP_CONCAT(u.name SEPARATOR '\n <br>') as tester_name FROM test_suite_run tsr, users u, test_suite ts 
        WHERE FIND_IN_SET(u.id, tsr.tester_id) AND ts.id = tsr.test_suite_id
        GROUP BY tsr.id ORDER BY tsr.id DESC LIMIT $limit, $id";

    $query = $this->db->query($sql);
    return $query->result();
}

控制器

public function display_test_suite_run_list_with_pagination() {
    $this->load->library('pagination');
    $config = array();
    $config["base_url"] = base_url() . "index.php/tester/display_test_suite_run_list_with_pagination";
    $total_row = $this->model_tester_test->record_count();
    $config["total_rows"] = $data["total_data_stored"] = $total_row;
    $config["per_page"] = 5;
    $config['use_page_numbers'] = false;
    $config['num_links'] = $total_row;
    $config['cur_tag_open'] = '&nbsp;<a class="current">';
    $config['cur_tag_close'] = '</a>';
    $config['next_link'] = 'Next';
    $config['prev_link'] = 'Previous';

    $this->load->library('pagination');
    $this->pagination->initialize($config);
    if ($this->uri->segment(3)) {
        $page = ($this->uri->segment(3));
    } else {
        $page = 0;
    }
    $data["value_of_test_suite_run"] = $this->model_tester_test->display_testSuiteRun($config["per_page"], $page);

    $str_links = $this->pagination->create_links();
    $data["links"] = explode('&nbsp;', $str_links);
    //this is for dropdown list search//this is for dropdown list search
    $data['get_testSuiteRunforSearchDropdown'] = $this->model_tester_test->get_testSuiteRunforSearchDropdown();
    // View data according to array.
    $this->layout->view('tester/view_test_suite_run_display', $data);
}

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    改变它

    $this->model_tester_test->display_testSuiteRun($config["per_page"], $page);
    

    如下

    $this->model_tester_test->display_testSuiteRun($page, $config["per_page"]);
    

    因为您使用的是原始 SQL 查询,其中 $limit 用作偏移量,$id 是要显示的行数

    【讨论】:

      猜你喜欢
      • 2021-11-11
      • 2013-04-28
      • 1970-01-01
      • 2022-08-19
      • 2014-07-25
      • 2016-04-07
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多