user7149801
user7149801

Reputation: 65

pagination limit and offset is not working in codeigniter

I want to create pagination in code-igniter. All works fine but $limit and $id is not working that's why my view is not going to next page. I tried in more way but didn't reach into my goal. anybody please help.

Model

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();
}

Controller

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);
}

Upvotes: 0

Views: 979

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

Change it

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

as following

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

because you are using raw SQL query where $limit is working as offset and $id is number of row to show

Upvotes: 1

Related Questions