当前位置:编程学习 > php >>

php mysql数据库操作分页类

答案:
复制代码 代码如下:

<?php
/*
* mysql数据库 分页类
* @package pagelist
* @author yytcpt(无影)
* @version 2008-03-27
* @copyrigth http://www.d5s.cn/
*/
/*
* 分页样式
.page{float: left;font: 11px Arial, Helvetica, sans-serif; padding:6px 0; margin: 0px 10%; margin-top: 10px;}
.page a, .page strong{padding: 2px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.page a:visited{padding: 2px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.page .break{padding: 2px 6px; border: none; background: #fff; text-decoration: none;}
.page strong{padding: 2px 6px; border-color: #999; font-weight: bold; font-size: 13px; vertical-align: top; background: #fff;}
.page a:hover{color: #fff; background: #0063DC; border-color: #036; text-decoration: none;}
.page a:hover div{color: #FFF;cursor: pointer !important;cursor: hand;}
*/
class pagelist{
var $page; //分页页码
var $sql; //分页sql
var $img_path; //图标路径
var $img; //图标名称
var $img_btn; //图标地址
var $page_size; //设置每页显示条数
var $num_btn; //设置数字分页的显示个数
var $total_pages; //一共分多少页
var $total_records; //一共有多少条记录
var $url;
var $table;
var $new_sql; //指定的SQL语句
var $db;
function __construct(){
global $db;
$this->db = $db;
$tmp_page = intval(trim($_GET["page"]));
$this->page = empty($tmp_page)?1:$tmp_page;
$this->set_table();
$this->page_size = 20;
$this->num_btn = 9;
$this->img_path = '/images/';
$this->img = array("ico_first.gif", "ico_front.gif", "ico_next.gif", "ico_last.gif");
}
function set_table(){
$this->table["tablename"] = "";
$this->table["id"] = "id";
$this->table["orderby"] = $this->table["id"];
$this->table["descasc"] = "DESC";
$this->table["fileds"] = "*";
$this->table["where"] = "";
}
function set_img(){
$this->img_btn[0] = "<img src='".$this->img_path.$this->img[0]."' alt='首页' border='0' align='absmiddle'/>";
$this->img_btn[1] = "<img src='".$this->img_path.$this->img[1]."' alt='上一页' border='0' align='absmiddle'/>";
$this->img_btn[2] = "<img src='".$this->img_path.$this->img[2]."' alt='下一页' border='0' align='absmiddle'/>";
$this->img_btn[3] = "<img src='".$this->img_path.$this->img[3]."' alt='末页' border='0' align='absmiddle'/>";
}
function set_show_page(){
$this->set_img(); //设置翻页图片路径
$this->set_url();
$this->set_total_records();
if ($this->total_records<$this->page_size){
$this->total_pages = 1;
}else{
$this->total_pages = ceil($this->total_records/$this->page_size);
}
if ($this->page>$this->total_pages){
$this->page = $this->total_pages;
}
}
function show_first_prv(){
if ($this->page==1){
$str = "<strong>".$this->img_btn[0]."</strong> <strong>".$this->img_btn[1]."</strong>";
}else{
$str = "<a href=> $str.= "<a href=> }
return $str;
}
function show_next_last(){
if ($this->page>=$this->total_pages){
$str = "<strong>".$this->img_btn[2]."</strong> <strong>".$this->img_btn[3]."</strong>";
}else{
$str = "<a href=> $str.= "<a href=> }
return $str;
}
function show_num_text(){
$str = " 转到第 <input id='go_num_text' type='text' value='".$this->page."' style='border:0;border-bottom:1px solid #CCC;text-align:center;width:20px;'/> 页 ";
$str.= "<a href=> return $str;
}
function show_num_select(){
if ($this->total_pages<50){
$str = "<select onchange=\"if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}\">";
for ($i=1; $i<=$this->total_pages; $i++){
$str.= "<option value='".$this->url.$i."' ".($this->page==$i ? " selected='selected'":"").">".$i."</option>";
}
$str.= "</select> ";
}else{
$str = "";
}
return $str;
}
function show_num_btn(){
if ($this->page>=1 and $this->page<=$this->total_pages){
$tmp_p = ($this->num_btn-1)/2;
if (($this->page - $tmp_p)<=0){
$start_p = 1;
}else{
if (($this->page-$tmp_p)>$this->num_btn and ($this->page-$tmp_p)>($this->total_pages - $this->num_btn+1)){
$start_p = $this->total_pages - $this->num_btn + 1;
}else{
$start_p = $this->page - $tmp_p;
}
}
if (($this->page+$tmp_p) < $this->total_pages){
$end_p = ($this->page + $tmp_p)<$this->num_btn?$this->num_btn:($this->page + $tmp_p);
if ($end_p>$this->total_pages){
$end_p = $this->total_pages;
}
}else{
$end_p = $this->total_pages;
}
}
$str = "";
for ($i=$start_p; $i<=$end_p; $i++){
if ($i==$this->page){
$str.= " <strong>".$i."</strong> ";
}else{
$str.= " <a href=> }
}
return $str;
}
function show_page_info(){
$str = " 共".$this->total_records."条/".$this->total_pages."页";
return $str;
}
function show_page(){
if ($this->total_records<1){
$this->set_show_page();
}

上一个:php xfocus防注入资料
下一个:php读取数据库信息的几种方法

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,