niexa123
注册会员

中级会员
UID 50950
精华
0
积分 152
帖子 259
金钱 152 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2004-11-18
状态 离线
|
发一个分页类
<?php
/* 翻页类 */ if(!defined("__CLASS_NAVPAGE__")) { define("__CLASS_NAVPAGE__",1); class Turnpage extends Base_Root { var $db_connect; //数据库连接类 var $CurrentPage; //当前页 var $PageRecNums = 20; //每页记录条数 var $PageNums = 0; //记录总页数 var $RecNums = 0; //总记录条数 var $strSQL; //sql语句 var $condition; //条件 var $strOrderby; // ---------- // method // ---------- /* 设置函数 $DB_site 数据库连接类 $sql sql语句 $orderby 按某数据项排列 $RecsPage 每页显示的记录条数 */ function query_exec($sql,$orderby="",$PageRecNums) { $this->strOrderby = $orderby; $this->strSQL = $sql; $this->PageRecNums = $PageRecNums; } /* 功 能:返回符记录总条数 参 数:null 返回值:int 描 述:该函数为外部接口函数用于 显示记录总数 */ function GetTotalRecords() { return $this->RecNums; } /* 功 能:返回总页数 参 数:null 返回值:int 描 述:该函数为外部接口函数用于 显示总页数 */ function GetTotalPages() { return $this->PageNums; } /* 功 能:计算记录总条数 参 数:null 返回值:null 描 述:该函数内部函数不要在外部调用该函数 */ function SetTotalRecords() { $this->RecNums = $this->db_connect->num_rows($this->db_connect->query($this->strSQL)); @mysql_free_result($res); } /* 功 能:计算总页数 参 数:null 返回值:null 描 述:该函数是内部函数不要在外部调用 */ function SetTotalPages() { $this->PageNums = Ceil($this->RecNums / $this->PageRecNums); } //取得每页记录条数 function GetRecsPage() { return $this->PageRecNums; } //有条件查询 function Query($condition) { $this->condtion = $condition; } //功 能:显示分页的页数 //参 数:$pages界面的显示页数 function PageList($param="") { $num = " 合计".$this->RecNums."记录 | "; //显示翻页 if($this->CurrentPage >1) $num .=" <a title=\"preview\" href=\"".basename($PHP_SELF)."?page=1"."$param\" class=\"link1\">首页</a> <a title=\"preview\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage - 1)."$param\" class=\"link1\">上一页</a>"; else $num .=" "; if($this->CurrentPage < $this->PageNums) $num .=" <a title=\"next\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage + 1)."$param\" class=\"link1\">下一页</a> <a title=\"next\" href=\"".basename($PHP_SELF)."?page=".$this->PageNums."$param\" class=\"link1\">尾页</a>"; else $num .=" "; $num .= " | 当前在".$this->CurrentPage."/".$this->PageNums."页 ".$this->PageRecNums."记录/页"; $num .=" | 转到:<SELECT onchange={javascript:window.open(this.options[this.selectedIndex].value,\"_self\")} name=select>"; for($i = 1;$i < ($this->PageNums+1);$i++) { $page = $i; if($this->CurrentPage == $i) $num .= "<OPTION value=\"".basename($PHP_SELF)."?page=$page$param\" selected>第".$i."页</OPTION>"; else $num .= "<OPTION value=\"".basename($PHP_SELF)."?page=$page$param\">第".$i."页</OPTION>"; } $num .="</SELECT>"; return $num; } function & GetRec() { if(!isset($_REQUEST["page"])) $this->CurrentPage = 1; else $this->CurrentPage = $_REQUEST["page"]; $this->SetTotalRecords(); $this->SetTotalPages(); $start = ($this->CurrentPage - 1) * $this->PageRecNums; $sql = $this->strSQL." ".$this->$condition." ".$this->strOrderby." limit $start,$this->PageRecNums"; return $this->db_connect->query($sql); } } global $DB,$xnavpage; $xnavpage = new Turnpage($DB); } ?> 具体实例可参照下面网站:
http://www.quanq.com
[ 本帖最后由 niexa123 于 2006-8-13 03:23 PM 编辑 ]
|  http://www.ml188.org |
|