질문Q #8040
Microsoft SQL Server 2000 pagination with CI (mssql)
PII2011-04-04 23:55:20
중복 된 것인지 모르겠습니다..
포럼에서 찾았으면 금방 이였을 것을 ...
원본은
http://codeigniter.com/forums/viewthread/139350/ 여기 입니다.
자세한것은 원본에서 보세요...
이렇게 옮겨 놔도 되는건지 모르겠습니다.
문제 되면 자삭하겠습니다...
model
function get_all_people() {
$this->db->select('*');
$this->db->from('people_table');
$result_count = $this->db->count_all_results();
$this->db->select('*');
$this->db->from('people_table');
$this->db->order_by('person_last_name', 'asc');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return array (
'results_count' => $result_count,
'results' => $query->result());
} else {
return null;
}
}
function get_paginated_people($limit, $offset) {
if ($offset == 0) {
$sql = "SELECT TOP $limit *
FROM people_table
ORDER BY person_last_name asc";
} else {
$sql = "SELECT TOP $limit *
FROM people_table
WHERE person_id NOT IN (
SELECT TOP $offset person_id
FROM people_table
ORDER BY person_last_name asc
)
ORDER BY person_last_name asc";
}
$query = $this->db->query($sql);
if ($query->result()) {
return $query->result();
} else {
return null;
}
}
controller
function index() {
//DEBUG
//$this->output->enable_profiler(TRUE);
$people_data = $this->peoplemodel->get_all_people();
//PAGINATION
$config['base_url'] = site_url('getpeople/index');
$config['total_rows'] = $people_data['results_count'];
$config['per_page'] = '20';
$this->pagination->initialize($config);
$data['page_links'] = $this->pagination->create_links();
$limit = $config['per_page'];
$offset = $this->uri->segment(3, 0) ? $option = $this->uri->segment(3, 0) : 0;
$paginated_people_data = $this->peoplemodel->get_paginated_people($limit, $offset);
foreach ($paginated_people_data as $person_data) {
$data['people'] .= '
<li>
' . strip_quotes($person_data->person_last_name) . ', ' . strip_quotes($person_data->person_first_name) . ' '
.auto_link($person_data->person_email) . '</li>';
}
$this->load->view('getpeople', $data);
}