<?php/*-------------------------------------------------------------------- $ module: page.class.php $ license: version 1.0 $ create: 2009-7-17 15:21:12 $ author: LovelyLife <master#onlyaa.com> $ copyright :Copyright 2006 onlyaa.com----------------------------------------------------------------------*/// 分页模板class CLASS_PAGE { var $html; var $url; var $visiblesize; // 显示长度 var $table; // 用来区分多表分页访问 var $page; // 地址中的查询字段 var $current; // 当前访问页 var $totalsize; // 记录总数 var $pagesize; // 分页大小 var $pagecount; // 页数 var $first; function __construct($cfg) { $this->html = ""; $this->url = ""; $this->first = 1; $this->visiblesize = 10; $this->page = "page"; // 默认分页大小为 10 $this->pagesize = intval($cfg["pagesize"]); if($this->pagesize < 1) { $this->pagesize = 10; } // 记录数 $this->totalsize = intval($cfg["totalsize"]); $this->pagecount = ceil($this->totalsize / $this->pagesize); $this->pagecount = max($this->pagecount, 1); // 修正页数为1的bug // 当前访问页 if($cfg["html"] == true) { $cur = intval($cfg["page"]); $cur = max(1, $cur); $this->current = min($this->pagecount, $cur); $this->first = $cfg["first"]; $this->url = $cfg["tpl"]; // $this->_htmlurl($cfg["tpl"]); } else { if(!isset($_GET[$this->page])) { $this->current = 1; } else { $cur = intval($_GET[$this->page]); $cur = max(1, $cur); $this->current = min($this->pagecount, $cur); } $this->_baseURL(); } //var_dump($this); } function CLASS_PAGE($cfg) { $this->__construct($cfg); } function GetCurrentPage() { return $this->current; } function _first(){ return 1; } function _prev() { return max(1, $this->current - 1); } function _next() { return min($this->current + 1, $this->pagecount); } function _last() { return $this->pagecount; } function __toString($mode = 1) { switch($mode) { case 2: break; case 3: break; default: $this->defaultview(); } return $this->html; } function defaultview() { $cur = $this->current; $pcount = $this->pagecount; if($cur > 1) { $this->html = " <a href=/"".$this->goto($this->_prev())."/"><font size=2>[<<]</font></a> "; } $buf = ""; // 分页缓冲区 $start = $cur - (floor($this->visiblesize/2)); $start = max(1, $start); $t = $cur + floor($this->visiblesize/2) - 1; // last visible page id $end = min($pcount, $t); // 显示分页长度 for($i=$start; $i <= $end; $i++) { if($i == $cur) { $buf .= "".$i." "; continue; } else { $buf .= "<a href=/"".$this->goto($i)."/">[{$i}]</a> "; } } $this->html .= $buf; // print("<br>cur:{$cur}<br>"); if($cur < $pcount) { $this->html .= "<a href=/"".$this->goto($this->_next())."/"><font size=2>[>>]</font></a>"; } // $this->html = "<div style=/"font-family:arial,宋体; font-size: 13px; padding-left:10px;font-size:14px;word-spacing:4px; text-align: left;/">".$this->html."</div>"; } function goto($pageid) { if($pageid > 1) { $url = str_ireplace("{id}", $pageid, $this->url); } else { $url = $this->first; } return $url; } function _baseURL() { $url = $_SERVER["REQUEST_URI"]; $pos = strpos($url, "?"); // 没有其他的参数 if($pos == -1) { $this->url=$url."?".$this->page."="; return; } // 存在其他参数 $params = split("&", $_SERVER["QUERY_STRING"]); $params2 = array(); foreach($params as $value) { $l = split("=", $value); if($l[0] != $this->page) { array_push($params2, $value); } } $this->url = $_SERVER["SCRIPT_NAME"]."?".implode($params2, "&")."&page={id}"; $this->first = str_ireplace("{id}", 1, $this->url); }}?>====================================修改后的内容<?phperror_reporting(E_ALL);define('SCR','index');require_once('global.php');require_once('page.class.php'); // 包含page类!$winduid && Showmsg('not_login');require_once(R_P.'require/header.php');mysql_select_db("bbs"); $exec="select nasipaddress,acctstarttime,acctstoptime,acctsessiontime,acctInputOctets,acctOutputOctets,acctterminatecause from radacct where username='$windid' order by acctstarttime desc";$result=mysql_query($exec); $num=mysql_num_rows($result);// 这里先分页,再查询sql $totalsize = $num; // 记录总数 $pageSize = 20; // 分页大小 $cfg = array("totalsize" => $totalsize,"pagesize" => $pageSize); $cfg["page"] = "pageid"; // 设置分页标识 url中问号后面 $pager = new CLASS_PAGE($cfg); // 创建分页对象 $sql = $exec." limit ".($pager->GetCurrentPage()-1)*$pageSize .",{$pageSize};"; // 组合分页查询sql// 分完页后,在执行分页查询的sql$result2=mysql_query($sql); $rsNum=mysql_num_rows($result2);if($rsNum <= 0) { echo"你还没有成功登录过VPN,哪儿来的详细记录?";} else {echo "<table width=100%>"; echo "<tr><td>"; echo "<font size=4><b>服务器</b></font></td>"; echo "<td>"; echo "<font size=4><b>开始时间</b></font></td>"; echo "<td>"; echo "<font size=4><b>停止时间</b></font>"; echo "<td>"; echo "<font size=4><b>时长</b></font></td>"; echo "<td>"; echo "<font size=4><b>上传</b></font></td>"; echo "<td>"; echo "<font size=4><b>下载</b></font></td>"; echo "<td>"; echo "<font size=4><b>中断原因</b></font></td></tr>";// 显示分页记录while($rs=mysql_fetch_object($result2)) { $nasipaddress = $rs->nasipaddress == "192.168.0.70" ? "国内1号加速服务器" : $rs->nasipaddress ; echo "<tr height=25px><td>"; echo "".$nasipaddress.""; echo "<td>"; echo "".$rs->acctstarttime."</td>"; echo "<td>"; echo "" .$rs->acctstoptime."</td>" ; echo "<td>"; echo "" .$rs->acctsessiontime."秒</td>" ; echo "<td>"; echo "" .$rs->acctInputOctets."字节</td>" ; echo "<td>"; echo "" .$rs->acctOutputOctets."字节</td>" ; echo "<td>"; echo "" .$rs->acctterminatecause."</td>" ; echo "</tr>"; } echo "</table>"; echo "<p>"; echo "</p>"; echo "用户:$windid"; echo "<p>"; echo "</p>"; echo "<p>"; echo "</p>"; echo "共查询到".$num."条记录"; echo "<hr />"; ///delete // echo yemiandaohang("acct.php?",$num,$perpage,$page); echo $pager->__toString(); // 输出}footer();?>