哪位帮忙看下这个分页类怎么调用,我说的是在查询语句下 分页php分页函数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这里是php调用页面,如下代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">li{width:100%; overflow:hidden; margin-top:20px; list-style:none;}a{display:block; height:30px; min-width:30px; text-align:center; font-size:14px; border:1px solid #d6d6d6; float:left; margin-left:10px; padding:3px 5px; line-height:30px; text-decoration:none; color:#666;}a:hover,a.here{background:#FF4500; border-color:#FF4500; color:#FFF;} </style></head> <body> <?phprequire_once('/page.php'); $param = array('totalRows'=>'100','pageSize'=>'2','currentPage'=>@$_GET['p'],'baseUrl'=>'/page_index.php?id=3'); $page1 = new Page($param);$page2 = new Page($param);$page3 = new Page($param);$page4 = new Page($param);$page5 = new Page($param);这中间应该是sql查询语句,但是分页函数怎么调用我却不知道怎么写了 echo '总记录数:100';echo '<hr />';echo '每页记录2条<hr/ >';echo '当前页码:'.$page1->getCurrentPage().'<hr />';echo '共计'.$page1->pageAmount().'页<hr />';echo '<li>'.$page1->pagination().'</li>';echo '<li>'.$page2->pagination('1').'</li>'; //默认为1,所以和不填写效果一样echo '<li>'.$page3->pagination('2').'</li>';echo '<li>'.$page4->pagination('3').'</li>';echo '<li>'.$page5->pagination('4').'</li>';?></body></html> 这个类只负责分页条的产生唯一可能与数据库查询有关的是参数数组 $param['totalRows'] 项因为待分页的总行数是查询得到的,所以这个查询应在 $param 赋值之前完成 楼主也够懒的了,我这里有个给你,样式都写好了<?phpclass Page { private $total; //数据表中总记录数private $listRows; //每页显示行数private $limit;private $uri; private $pageNum; //页数private $config=array('header'=>"个记录", "prev"=>"上一页", "next"=>"下一页", "first"=>"首 页", "last"=>"尾 页"); private $listNum=8;/* $total 11. * $listRows 12. */ public function __construct($total, $listRows=10, $pa=""){ $this->total=$total; $this->listRows=$listRows; $this->uri=$this->getUri($pa); $this->page=!empty($_GET["page"]) ? $_GET["page"] : 1; $this->pageNum=ceil($this->total/$this->listRows); $this->limit=$this->setLimit(); } private function setLimit(){ return "Limit ".($this->page-1)*$this->listRows.", {$this->listRows}"; } private function getUri($pa){ $url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"], '?')?'':"?").$pa; $parse=parse_url($url); if(isset($parse["query"])){ parse_str($parse['query'],$params); unset($params["page"]); $url=$parse['path'].'?'.http_build_query($params); } return $url; } public function __get($args){ if($args=="limit") return $this->limit; else return null; } private function start(){ if($this->total==0) return 0; else return ($this->page-1)*$this->listRows+1; } private function end(){ return min($this->page*$this->listRows,$this->total); } private function first(){ if($this->page==1) $html.=''; else $html.="<li><a href='{$this->uri}&page=1'>{$this->config["first"]}</a></li>"; return $html; } private function prev(){ if($this->page==1) $html.=''; else $html.="<li><a href='{$this->uri}&page=".($this->page-1)."'>{$this->config["prev"]}</a></li>"; return $html; } private function pageList(){ $linkPage=""; $inum=floor($this->listNum/2); for($i=$inum; $i>=1; $i--){ $page=$this->page-$i; if($page<1) continue; $linkPage.="<li><a href='{$this->uri}&page={$page}'>{$page}</a></li>"; } $linkPage.="<li><a href='#' class='here'>{$this->page}</a></li>";for($i=1; $i<=$inum; $i++){ $page=$this->page+$i; if($page<=$this->pageNum) $linkPage.="<li><a href='{$this->uri}&page={$page}'>{$page}</a></li>";else break; }return $linkPage;}private function next(){ if($this->page==$this->pageNum)$html.=''; else $html.="<li><a href='{$this->uri}&page=".($this->page+1)."'>{$this->config["next"]}</a></li>"; return $html;}private function last(){ if($this->page==$this->pageNum)$html.='';else$html.="<li><a href='{$this->uri}&page=".($this->pageNum)."'>{$this->config["last"]}</a></li>";return $html;}/*private function goPage(){return ' <input type="text" class="inputall input50" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}" value="'.$this->page.'" style="width:25px"> <input type="button" value="GO" style="width:45px;height:30;line-height:30px;border-radius:4px;" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'&page=\'+page+\'\'"> ';}*/private function goPage(){return ' <input type="text" class="inputall input50" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}" value="'.$this->page.'" style="width:25px"><input type="button" value="GO" style="width:45px;height:30;line-height:30px;border-radius:4px;" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'&page=\'+page+\'\'"> ';}function fpage($display=array(0,1,2,3,4,5,6,7,8)){$html[0]="共有<b>{$this->total}</b>{$this->config["header"]} ";$html[1]=" 每页显示<b>".($this->end()-$this->start()+1)."</b>条,本页<b>{$this->start()}-{$this->end()}</b>条 "; $html[2]=" <b>{$this->page}/{$this->pageNum}</b>页 ";$html[3]=$this->first();$html[4]=$this->prev();$html[5]=$this->pageList();$html[6]=$this->next();$html[7]=$this->last();$html[8]=$this->goPage();$fpage='';foreach($display as $index){ $fpage.=$html[$index];} return $fpage;} }?>具体调用方法:$num=15; //每页显示数 $page=new page($total,$num); $result=$db->query("select * from ".$db->table('article').$where." order by addtime desc {$page->limit}"); 循环 <?php echo $page->fpage(array(3,4,5,6,7,0,1,2,8));?> //php分页类调用,这些数字可以去类文件里面看<span class="fenye"><ul class="fr"><?php echo $page->fpage(array(3,4,5,6,7,8));?></ul></span>这是我调用的CSS样式文件.fenye li{float:left; font-family:Arial, Helvetica, sans-serif; margin-left:6px; display:inline; line-height:30px;}.fenye a{display:block;height:30px; min-width:30px; text-align:center; font-size:14px; border:1px solid #d6d6d6; float:left; margin-left:3px; padding:3px 5px;line-height:30px;text-decoration:none;color:#666;}.fenye a:hover{background:#FF4500;border-color:#FF4500; color:#FFF;}.fenye a.here{background:#FF4500;border-color:#FF4500; color:#FFF;}.fenye .sel{background:#E5EDF2; color:#333; font-weight:bold; border:1px #C2D5E3 solid; padding:0 12px; border-radius:4px}下面上效果图: 求一正则 多条件搜索+伪静态规则+分页方案 com生成excel的问题,高手请进 我的zend不能识别php,那位高手帮帮忙? 显示和隐藏的问题 请问php+access能实现吗? php模板高级应用 浏览器的默认语言总是西欧字符,怎样改换? 有谁用过phpBB建立论坛的?小弟遇到点问题,想请教一下! PHP到了生死存亡的时候了吗? 一个搜索框内2个form 2个按钮 如何实现? 新手求助!!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
li{width:100%; overflow:hidden; margin-top:20px; list-style:none;}
a{display:block; height:30px; min-width:30px; text-align:center; font-size:14px; border:1px solid #d6d6d6; float:left; margin-left:10px; padding:3px 5px; line-height:30px; text-decoration:none; color:#666;}
a:hover,a.here{background:#FF4500; border-color:#FF4500; color:#FFF;}
</style>
</head>
<body>
<?php
require_once('/page.php');
$param = array('totalRows'=>'100','pageSize'=>'2','currentPage'=>@$_GET['p'],'baseUrl'=>'/page_index.php?id=3');
$page1 = new Page($param);
$page2 = new Page($param);
$page3 = new Page($param);
$page4 = new Page($param);
$page5 = new Page($param);这中间应该是sql查询语句,但是分页函数怎么调用我却不知道怎么写了
echo '总记录数:100';
echo '<hr />';
echo '每页记录2条<hr/ >';
echo '当前页码:'.$page1->getCurrentPage().'<hr />';
echo '共计'.$page1->pageAmount().'页<hr />';
echo '<li>'.$page1->pagination().'</li>';
echo '<li>'.$page2->pagination('1').'</li>'; //默认为1,所以和不填写效果一样
echo '<li>'.$page3->pagination('2').'</li>';
echo '<li>'.$page4->pagination('3').'</li>';
echo '<li>'.$page5->pagination('4').'</li>';
?>
</body>
</html>
唯一可能与数据库查询有关的是参数数组 $param['totalRows'] 项
因为待分页的总行数是查询得到的,所以这个查询应在 $param 赋值之前完成
class Page {
private $total; //数据表中总记录数
private $listRows; //每页显示行数
private $limit;
private $uri;
private $pageNum; //页数
private $config=array('header'=>"个记录", "prev"=>"上一页", "next"=>"下一页", "first"=>"首 页", "last"=>"尾 页");
private $listNum=8;
/* $total 11. * $listRows 12. */
public function __construct($total, $listRows=10, $pa=""){
$this->total=$total;
$this->listRows=$listRows;
$this->uri=$this->getUri($pa);
$this->page=!empty($_GET["page"]) ? $_GET["page"] : 1;
$this->pageNum=ceil($this->total/$this->listRows);
$this->limit=$this->setLimit();
}
private function setLimit(){
return "Limit ".($this->page-1)*$this->listRows.", {$this->listRows}";
}
private function getUri($pa){
$url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"], '?')?'':"?").$pa;
$parse=parse_url($url);
if(isset($parse["query"])){
parse_str($parse['query'],$params);
unset($params["page"]);
$url=$parse['path'].'?'.http_build_query($params);
}
return $url;
}
public function __get($args){
if($args=="limit")
return $this->limit;
else
return null;
}
private function start(){
if($this->total==0)
return 0;
else
return ($this->page-1)*$this->listRows+1;
}
private function end(){
return min($this->page*$this->listRows,$this->total);
}
private function first(){
if($this->page==1)
$html.='';
else
$html.="<li><a href='{$this->uri}&page=1'>{$this->config["first"]}</a></li>";
return $html;
}
private function prev(){
if($this->page==1)
$html.='';
else
$html.="<li><a href='{$this->uri}&page=".($this->page-1)."'>{$this->config["prev"]}</a></li>";
return $html;
}
private function pageList(){
$linkPage="";
$inum=floor($this->listNum/2);
for($i=$inum; $i>=1; $i--){
$page=$this->page-$i;
if($page<1)
continue;
$linkPage.="<li><a href='{$this->uri}&page={$page}'>{$page}</a></li>";
}
$linkPage.="<li><a href='#' class='here'>{$this->page}</a></li>";
for($i=1; $i<=$inum; $i++){
$page=$this->page+$i;
if($page<=$this->pageNum)
$linkPage.="<li><a href='{$this->uri}&page={$page}'>{$page}</a></li>";
else
break;
}
return $linkPage;
}
private function next(){
if($this->page==$this->pageNum)
$html.='';
else
$html.="<li><a href='{$this->uri}&page=".($this->page+1)."'>{$this->config["next"]}</a></li>";
return $html;
}
private function last(){
if($this->page==$this->pageNum)
$html.='';
else
$html.="<li><a href='{$this->uri}&page=".($this->pageNum)."'>{$this->config["last"]}</a></li>";
return $html;
}
/*private function goPage(){
return ' <input type="text" class="inputall input50" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}" value="'.$this->page.'" style="width:25px"> <input type="button" value="GO" style="width:45px;height:30;line-height:30px;border-radius:4px;" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'&page=\'+page+\'\'"> ';
}*/
private function goPage(){
return ' <input type="text" class="inputall input50" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}" value="'.$this->page.'" style="width:25px"><input type="button" value="GO" style="width:45px;height:30;line-height:30px;border-radius:4px;" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'&page=\'+page+\'\'"> ';
}
function fpage($display=array(0,1,2,3,4,5,6,7,8)){
$html[0]="共有<b>{$this->total}</b>{$this->config["header"]} ";
$html[1]=" 每页显示<b>".($this->end()-$this->start()+1)."</b>条,本页<b>{$this->start()}-{$this->end()}</b>条 ";
$html[2]=" <b>{$this->page}/{$this->pageNum}</b>页 ";
$html[3]=$this->first();
$html[4]=$this->prev();
$html[5]=$this->pageList();
$html[6]=$this->next();
$html[7]=$this->last();
$html[8]=$this->goPage();
$fpage='';
foreach($display as $index){
$fpage.=$html[$index];
}
return $fpage;
}
}
?>具体调用方法:
$num=15; //每页显示数
$page=new page($total,$num);
$result=$db->query("select * from ".$db->table('article').$where." order by addtime desc {$page->limit}");
循环
<?php echo $page->fpage(array(3,4,5,6,7,0,1,2,8));?> //php分页类调用,这些数字可以去类文件里面看
<span class="fenye"><ul class="fr"><?php echo $page->fpage(array(3,4,5,6,7,8));?></ul></span>这是我调用的
CSS样式文件
.fenye li{float:left; font-family:Arial, Helvetica, sans-serif; margin-left:6px; display:inline; line-height:30px;}
.fenye a{display:block;height:30px; min-width:30px; text-align:center; font-size:14px; border:1px solid #d6d6d6; float:left; margin-left:3px; padding:3px 5px;line-height:30px;text-decoration:none;color:#666;}
.fenye a:hover{background:#FF4500;border-color:#FF4500; color:#FFF;}
.fenye a.here{background:#FF4500;border-color:#FF4500; color:#FFF;}
.fenye .sel{background:#E5EDF2; color:#333; font-weight:bold; border:1px #C2D5E3 solid; padding:0 12px; border-radius:4px}
下面上效果图: