TIP게시판

제목 Microsoft SQL Server 2000 pagination with CI (mssql)
글쓴이 PII 작성시각 2011/04/04 23:55:20
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 17377   RSS

중복 된 것인지 모르겠습니다..

포럼에서 찾았으면 금방 이였을 것을 ...

원본은 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(30) ? $option $this->uri->segment(30) : 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);
    



태그 pagination,mssql
 다음글 CI 2.0.2 캐싱 버그 수정 (4)
 이전글 전에 xmlToArray가 쓰기 불편해서 이걸로 변경했...

댓글

변종원(웅파) / 2011/04/05 09:04:07 / 추천 0
모델의 top이 관건이죠. Mysql과는 다른.. ^^