【www.gdgbn.com--页面特效】
page_total_rows - 每页展示数量 默认值20
$total_rows - 总计数据条目数
$totpages - 总页数计算
$pages_current - 当前页面
利用url参数传递 当前页码 url参数名称 pages
$style - 页码展示样式可以通过外部访问样式属性进行修改
***********************使用方法**********************
调用该类
$pages = new pages;
调用该类后请修改数据集总条数
$pages->total_rows = $totrows;
//$pages->main();方法将返回limit需要的2个参数 关联数组的a,b2个元素
$limit = $pages->main();
通过访问不同方法即可展示不同的功能!
欢迎批评指正 联系qq 5213606
*/
class pages{
public $page_total_rows = 20;//每页展示数量
public $total_rows;//总计数据条目数
public $totpages;//总页数
public $current_url;//当前页面名称
private $ask; //是否出现问号
public $style ="
";
//核心计算 并以数组的形式返回查询sql 语句的必须值 limit a,b;
function main(){
$this->totpages = ceil($this->total_rows/$this->page_total_rows);//总页数计算
//获得当前页码-------------------
if(!isset($_get["pages"]))
{
$this->pages_current = 1;
}else
{
$this->pages_current = intval($_get["pages"]);
//判断页面不为0
if($this->pages_current < 1){
$this->pages_current = 1;
}
//判断页面不能大于最大页码数量
if($this->pages_current > $this->totpages){
$this->pages_current = $this->totpages;
}
//注销url 参数 pages 和 total_rows 为了更好的传递其他url参数
if(isset($_get["pages"])){unset($_get["pages"]);}
if(isset($_get["total_rows"])){unset($_get["total_rows"]);}
}
//获得当前页码--------------------
$limit["a"] = $start = ($this->pages_current - 1)*$this->page_total_rows;
$limit["b"] = $this->page_total_rows;
//获得当前页面名称
$urlin = explode("/",$_server["php教程_self"]);
$tot_url = sizeof($urlin);
$this->current_url =$urlin[$tot_url-1];
//获得当前页面传递的url
if(sizeof($_get) > 0){
foreach($_get as $key=>$values){
$urlsget .= $key."=".$values."&";
}
$this->current_url .= "?".$urlsget;
$this->ask = "";
}else{$this->ask = "?";}
//输出样式
echo $this->style;
return $limit;
}
//展示分页
//1 第一页
function firstpage(){
echo "current_url."">首页";
}
//2 上一页
function prepage(){
echo "current_url.$this->ask."pages=".($this->pages_current-1)."">上一页";
}
//3 下一页
function nextpage(){
echo "current_url.$this->ask."pages=".($this->pages_current+1)."">下一页";
}
//4 最后一页
function lastpage(){
echo "current_url.$this->ask."pages=".($this->totpages)."">尾页";
}
//中间过渡页
function morepage(){
if($this->pages_current == 1){$newtj = $this->pages_current+9;}
elseif($this->pages_current == 2){$newtj = $this->pages_current+8;}
elseif($this->pages_current == 3){$newtj = $this->pages_current+7;}
else{$newtj = $this->pages_current+6;}
for($i=$this->pages_current-3;$i<=$newtj;$i++){
if($i==$this->pages_current){$strong =""; $strong2 ="";}else{$strong="";$strong2="";}
if($i >=1){echo "current_url.$this->ask."pages=".$i."">".$strong.$i.$strong2."";}
if($i >= $this->totpages){
break;
}
}
}
//跳转页面
function changepage(){
echo "";
}
}
?>
该类可以自动识别 url 参数 避免了一般分页类 丢失url参数问题
样式 可以通过style属性 进行修改
提供 首页 上一页 下一页 尾页 中间 过渡页 跳转菜单功能