在codeigniter中创建分页

时间:2016-01-24 05:24:27

标签: php sql-server codeigniter pagination

我正在尝试对从数据库中检索的数据进行分页。 但是,我一直收到此错误

  

消息:odbc_exec():SQL错误:[Microsoft] [ODBC SQL Server   驱动程序] [SQL Server]错误的语法在' 1'。,SQL状态37000 in   SQLExecDirect的。

控制器代码

function __construct() {
    parent::__construct();
}

function index() {
    // return to previous page
    redirect(base_url());
}

function ci_pagination() {
    $this->load->library('pagination');
    $this->load->library('table');
    $this->load->model('demo/Demo_page');

    //$result_per_page = 5;  // the number of result per page

    $config['base_url'] = base_url() . '/demo/ci_pagination/';
    $config['total_rows'] = $this->Demo_page->count_items();
    $config['per_page'] = '1';
    $config['num_links'] = 10;
    $this->pagination->initialize($config);

    $datatable = $this->Demo_page->get_items($config['per_page'], $this->uri->segment(3));

    $this->load->view('demo/ci_pagination', array(
        'datatable' => $datatable,
        'result_per_page' => $result_per_page
    ));
    }
}

模型代码

<?php
class Demo_page extends CI_Model {
    function __construct() {
        parent::__construct();
        $this->db = $this->load->database('online', TRUE);
    }

    function count_items(){
        return $this->db->count_all('o2o_banner');
    }

    function get_items($limit, $offset){
        $data = array();
        $this->db->limit($limit, $offset);
        $Q = $this->db->get('o2o_banner');
        if($Q->num_rows() > 0){
            foreach ($Q->result_array() as $row){
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
}

0 个答案:

没有答案