![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
相关问题
CODE: <?php /* 翻页类 */ class Turnpage extends base_root { var $db_connect; //数据库连接类 var $CurrentPage; //当前页 var $PageRecNums = 20; //每页记录条数 var $PageNums = 0; //记录总页数 var $CurrentBigPage; //当前大页 var $BigPageRecNums = 2; //每大页小页数 var $BigPageNums = 0; //大页总数 var $RecNums = 0; //总记录条数 var $strSQL; //sql语句 var $condition; //条件 var $strOrderby; /*/ internal use only var $db_server = "mysql"; var $db_hostname = "localhost"; var $db_username = ""; var $db_password = ""; var $db_name = ""; var $db_connect = ""; 构造函数 $DB_site 数据库连接类 $sql sql语句 $orderby 按某数据项排列 $RecsPage 每页显示的记录条数 function InitDB($server,$host,$username,$pwd,$db) { $this->db_server = $server; $this->db_hostname = $host; $this->db_username = $username; $this->db_password = $pwd; $this->db_name = $db; $this->db_connect = new DB_Sql_vb; $this->db_connect->connect($this->db_hostname,$this->db_username,$this->db_password,$this->db_name); //$this->db_connect->debug=true; } */ /* 设置函数 $DB_site 数据库连接类 $sql sql语句 $orderby 按某数据项排列 $RecsPage 每页显示的记录条数 */ function query_exec($sql,$orderby="",$PageRecNums,$BigPageRecNums) { $this->strOrderby = $orderby; $this->strSQL = $sql; $this->PageRecNums = $PageRecNums; $this->BigPageRecNums = $BigPageRecNums; } /* 功 能:返回符记录总条数 参 数: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); } /* 功 能:计算大页总页数 参 数:null 返回值:null 描 述:该函数是内部函数不要在外部调用 */ function SetTotalBigPages() { $this->BigPageNums = Ceil(Ceil($this->RecNums / $this->PageRecNums)/$this->BigPageRecNums); } //取得每页记录条数 function GetRecsPage() { return $this->PageRecNums; } //有条件查询 function Query($condition) { $this->condtion = $condition; } //功 能:显示分页的页数 //参 数:$pages界面的显示页数 function PageList($param="") { //显示翻页 if($this->CurrentBigPage >1) $num .=" <a title=\"preview\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage - $this->BigPageRecNums)."$param\" class=\"link1\">首页</a>"; else $num .="首页"; for($i = 1;$i < ($this->BigPageRecNums+1)&& $page < $this->PageNums;$i++) { $page = $i + (($this->CurrentBigPage-1)*$this->BigPageRecNums); if($this->CurrentPage == $i) $num .= " <a href=\"".basename($PHP_SELF)."?page=$page$param\" class=\"link1\"><strong><font color=\"#FF6F6F\">第".$page."页</font></strong></a>"; else $num .= " <a href=\"".basename($PHP_SELF)."?page=$page$param\" class=\"link1\">第".$page."页</a>"; } if($this->CurrentBigPage < $this->BigPageNums) $num .=" <a title=\"next\" href=\"".basename($PHP_SELF)."?page=".($this->CurrentPage + $this->BigPageRecNums)."$param\" class=\"link1\">尾页</a>"; else $num .=" 尾页"; $num .= " 合计 ".$this->RecNums." 记录 | 当前在".$this->CurrentPage."/".$this->PageNums."页"; return $num; } function & GetRec() { if(!isset($_REQUEST["page"])) $this->CurrentPage = 1; else $this->CurrentPage = $_REQUEST["page"]; $this->CurrentBigPage = Ceil($this->CurrentPage / $this->BigPageRecNums); $this->SetTotalRecords(); $this->SetTotalPages(); $this->SetTotalBigPages(); $start = ($this->CurrentPage - 1) * $this->PageRecNums; $sql = $this->strSQL." ".$this->$condition." ".$this->strOrderby." limit $start,$this->PageRecNums"; return $this->db_connect->query($sql); } } ?> |
提问者:che361 08-22 15:03
答复

