|
|
2#

楼主 |
发表于 2007-10-5 11:28:17
|
只看该作者

- public function __construct($sql,$CycNum = 5){
- if(!@mysql_ping()){
- echo "Please check your database link";
- exit;
- }
- if(is_numeric($CycNum)){
- $this->CycNum = $CycNum;
- }else{
- $this->CycNum = $this->CycNum;
- }
- if(trim($sql) != ""){
- /*if(preg_match("/limit/",$sql)){
- list($sql,$limit) = explode("limit",$sql);
- }else{
- list($sql,$limit) = explode("LIMIT",$sql);
- }
- $this->QueryString = $sql;
- list($cnt1,$cnt2) = explode(",",$limit);
- if(!empty($cnt2)){
- $this->PageSize = $cnt2;
- }elseif(!empty($cnt1)){
- $this->PageSize = $cnt1;
- }else{
- $this->PageSize = $this->PageSize;
- }*/
- /**修改于2006年11月23日,解决出现Notice: Undefined offset: 2***/
- if(preg_match("/limit/",$sql)){
- list($sql,$limit) = explode("limit",$sql);
- }else if(preg_match("/LIMIT/",$sql)){
- list($sql,$limit) = explode("LIMIT",$sql);
- }
- //$this->QueryString = $sql;
- if(isset($limit)){
- list($cnt1,$cnt2) = explode(",",$limit);
- if(!empty($cnt2)){
- $this->PageSize = $cnt2;
- }elseif(!empty($cnt1)){
- $this->PageSize = $cnt1;
- }else{
- $this->PageSize = $this->PageSize;
- }
- }
- $this->QueryString = $sql;
- unset($cnt1);
- unset($cnt2);
- }
- }
- /**
- *
- * @description 获取相应规定数目的记录
- * 并计算出总记录数,总页数等比较重要的参数
- * @param int $Sortid
- * 排序ID
- * @param bool $IsEncode
- * 页号是否加密,true为加密,false为不加密
- * @return string
- */
- public function StartPage($Sortid,$IsEncode = false,$IsNeedStat = false,$SortMethod = "down"){
- $Result = mysql_query($this->QueryString);
- $this->RecordNum = @mysql_num_rows($Result);
- $this->TotalPage = ceil($this->RecordNum/$this->PageSize);
- /*******************************************************
- * 初始化类属性IsNeedStat
- *******************************************************/
- if($IsNeedStat === true or $IsNeedStat === false){
- $this->IsNeedStat = $IsNeedStat;
- }else{
- echo "Warning:方法StartPage中的参数IsNeedStat只能是bool";
- }
- /*******************************************************
- * 初始化类属性IsEncode
- *******************************************************/
- if($IsEncode === true or $IsEncode === false){
- $this->IsEncode = $IsEncode;
- }else{
- echo "Warning:方法StartPage中的参数IsEncode只能是bool";
- }
-
- /*******************************************************
- *接收从url中传过来的当前页数,如果非数字,刚获取其整数值
- *******************************************************/
- if(isset($_REQUEST['NowPage'])){
- $this->NowPage = intval($_REQUEST['NowPage']);
- }
-
- /*******************************************************
- *根据$IsEncode的值来判断页号是否解密,如果$IsEncode的值非bool,
- *则给出警告信息,但并不影响程序执行,且默认不加密.
- *******************************************************/
- if($this->IsEncode === true){
- $this->NowPage = intval($this->StrDecode($_REQUEST['NowPage']));
- }
- //排列顺序 up 升序 down 降序
- if(isset($SortMethod) && $SortMethod == "up"){
- $SortMethod = "ASC";
- }elseif(isset($SortMethod) && $SortMethod == "down"){
- $SortMethod = "DESC";
- }else{
- echo "Warning:方法StartPage中的参数SortMethod只能是down或者up";
- }
- if(!isset($this->NowPage)){
- $this->NowPage = 1;
- }elseif($this->NowPage <= 0){
- $this->NowPage = 1;
- }elseif($this->NowPage > $this->TotalPage){
- $this->NowPage = $this->TotalPage;
- }else{
- $this->NowPage = $this->NowPage;
- }
- $OffSet = $this->PageSize * ($this->NowPage -1);
- $sql = $this->QueryString." ORDER BY ".$Sortid." ".$SortMethod." LIMIT ".$OffSet.",".$this->PageSize;
- return $sql;
- }
- /**
- *
- * @description
- * 翻页按扭的显示,如:首页 上页 下页 末页,可以定制自定义翻页按扭样式
- * 此函数也是 外面调用此类的入口.将返回经处理后的sql语
- * @param array $ButtonArray
- * 翻页按扭形式,用户可随意定制:如:
- * $ButtonArray = array("首页","上页","下页","末页");
- * @param string $JumpType
- * 附加选项,通过能参数,可定制跳转框,select 下拉跳转框,text 文
- * 本输入跳转框,none 不定制任何跳转框
- * @param bool $IsDisNum
- * 是否显示循环分页,true 显示 false 不显示;如:
- * 1 2 3 4 5 6 7 8 9 10
- * @return string
- */
- public function EndPage($ButtonArray,$JumpType = "none",$IsDisNum = false){
- $FirstPage = 1;
- $PrePage = $this->NowPage - 1;
- $NextPage = $this->NowPage + 1;
- $LastPage = $this->TotalPage;
- /**
- * 根据参数$ButtomArray来得到用户定制的按扭,如果参数给出类型
- * 不正确,则采用系统默认按扭
- */
- if(!is_array($ButtonArray) or count($ButtonArray) != 4){
- $ButtonArray = array("First","Precede","Next","Last");
- }
- if($this->IsNeedStat === true){
- $ReturnStr = "".$this->PageStat()."";
- }else{
- $ReturnStr = "";
- }
- $ReturnStr .= $this->ToPage($FirstPage,$ButtonArray[0],"First");
- $ReturnStr .= " ";
- $ReturnStr .= $this->ToPage($PrePage,$ButtonArray[1],"Pre");
- if($IsDisNum === true){
- $ReturnStr .= " ".$this->DisPageNum()." ";
- }elseif($IsDisNum === false){
- $ReturnStr .= " ";
- }else{
- /**
- * 对参数的合法性,进行审核
- */
- echo ('Warning:方法EndPage()中参数$IsDisNum的类型是bool,只能是 true或者false
- ');
- $ReturnStr .= " ";
- }
- $ReturnStr .= $this->ToPage($NextPage,$ButtonArray[2],"Next");
- $ReturnStr .= " ";
- $ReturnStr .= $this->ToPage($LastPage,$ButtonArray[3],"Last");
- $ReturnStr .= " ";
- if($JumpType === 'select'){
- $ReturnStr .= $this->JumpSelect('select');
- }elseif($JumpType === 'text'){
- $ReturnStr .= $this->JumpSelect('text');
- }elseif($JumpType === 'none'){
- //待写入
- }else{
- echo ('Warning:方法EndPage()中参数$JumpType 的值只能是 select text none
- ');
- }
- return $ReturnStr;
- }
- /**
- *
- * @description
- * 创建翻页按扭,并根据$Flag 的值来设置按扭是否可用,即:按
- * 扭是否带有链接,此此函数外界不可访问,属于该类私有方法
- * @param int $Page 将要跳转的页数
- * @param string $Msg 跳转按扭名称
- * @param string $Flag 按扭显示类型的判断
- * @return string
- */
复制代码 |
|