|
自己写的一个分页类,SQL语句是参考网上的一些资料写出来的,速度很快~
欢迎各位大虾拍砖,指出不足和需要改进的地方,谢谢!
分页类见附件,Sql_pages.php . 用法如下:
1、我在是模型里调用的,模型代码如下:
PHP复制代码 function get_lists ( $_page = 1, $_condition = '', $_page_size = 10, $_order = 'ASC', $_page_url = '', $_page_length = 9 )
{
$db_data = array(
'current_page' => $_page,
'fields' => 'admin_id, admin_name, admin_role, admin_this_ip, admin_this_time, admin_last_ip, admin_last_time, admin_add_time',
'tables' => $this->db_table,
'condition' => $_condition,
'order_by' => 'admin_id',
'page_size' => $_page_size,
);
$this->CI->load->library('sql_pages', $db_data);
$result = $this->CI->sql_pages->get_result($_order);
$this->page_str = $this->CI->sql_pages->show_pages($_page_length, $_page_url);
return $result;
}
function get_pages ()
{
return $this->page_str;
} 复制代码
2、控制器代码
PHP复制代码 $condition = ( 'all' == $role ) ? '1=1' : 'admin_role="' . $role . '"';
$page_url = $data['site_url'] . '/admin/lists/' . $role . '/';
$data['admin_lists'] = $this->admin->get_lists( $page, $condition, 10, 'ASC', $page_url, 9);
$data['admin_pages'] = $this->admin->get_pages(); 复制代码
3、CSS 分页页码样式
CSS复制代码 #pages { float:left; padding:3px 0 3px 5px;}
#pages a{ display:block; float:left; margin-left:3px; padding:0 6px; height:21px; line-height:21px; color:#333; border:1px solid #cccecc; color:#666; background:#fff;}
#pages a:hover { border:1px solid #2286b3; color:#2286b3; }
#pages a.this { padding:0 6px; height:20px; line-height:20px; border:1px solid #2286b3; color:#fff; font-weight:bold; background:#2286b3;}
#pages a.disabled { border:1px solid #E8E8E8; color:#b1b0b0; }
#pages a.text{padding-top:2px; height:19px; line-height:19px;} 复制代码 |
评分
-
查看全部评分
|