因为MSSQL不提供带偏移量的查询语句,所以本人很头疼,后来在群友的支持下终于完成并实现了,现在将控制器部分的代码粘贴如下,希望象我一样的菜鸟能有所收获.
复制内容到剪贴板PHP 代码:
function advstation
() { //初始参数设置 $now_table=
'advstation';
$base_url=
'/index.php/webadvmag/advstation/';
$per_page=
10;
$segment_value=
3;
//调用类库 $this->
load->
helper(array('form',
'url'));
//调用分页类 $this->
load->
library('pagination');
$config['base_url'] =
$base_url;
$sum=
$config['total_rows'] =
$this->
db->
count_all('advstation');
$config['per_page'] =
$per_page;
$config['uri_segment']=
$segment_value;
$this->
pagination->
initialize($config);
//组织mssql查询语句开始 if(($this->
uri->
segment(3))>
0){ $offset=
$this->
uri->
segment($segment_value);
}else{ $offset=
0;
} //最后一页条数设置 if(($sum-
$offset)<
$per_page){ $per_page=
$sum-
$offset;
} $sql =
"SELECT * FROM (select top ".
$per_page.
" * from (select top ".
($per_page+
$offset).
" advstationid,advstation,advsize,channel from advstation a,channels b where a.channelid=b.channelid order by advstationid DESC) AS A order by advstationid ASC) AS B ORDER BY advstationid DESC";
//查询语句组织完成 $query=
$this->
db->
query($sql);
//取得查询结果及分页信息 $data['pages']=
$this->
pagination->
create_links();
$data[$now_table.
'_fields'] =
$query->
result_array();
/*分页显示结束*/ //调用视图 $this->
load->
view('adminweblogin/adv_station_list',
$data);
}