调用
<?php
$pageNav = new pageNav( $page , $totalPages ) ;
$link = "search.php";
$pageNav->link_expression = array(
'startPage'=>"{{link}}.php?so=$so",
'prePage'=>"{{link}}?so=$so&p={{pre_page}}",
'nextPage'=>"{{link}}?so=$so&p={{next_page}}",
'endPage'=> "{{link}}?so=$so&p={{end_page}}",
'selectPage'=> "'{{link}}?so=$so&p='+this.value"
);
$pageLinks=$pageNav->getPagesLinks( $link );
$pageCounter=$pageNav->getPagesCounter( $link );
//echo $pageLinks . $pageCounter;echot($pageLinks );echot($pageCounter );
?>
$pageNav = new pageNav( $page , $totalPages ) ;
$link = "search.php";
$pageNav->link_expression = array(
'startPage'=>"{{link}}.php?so=$so",
'prePage'=>"{{link}}?so=$so&p={{pre_page}}",
'nextPage'=>"{{link}}?so=$so&p={{next_page}}",
'endPage'=> "{{link}}?so=$so&p={{end_page}}",
'selectPage'=> "'{{link}}?so=$so&p='+this.value"
);
$pageLinks=$pageNav->getPagesLinks( $link );
$pageCounter=$pageNav->getPagesCounter( $link );
//echo $pageLinks . $pageCounter;echot($pageLinks );echot($pageCounter );
?>
类
<?php
/**
* Page navigation class
* bailing
* 2006-11-03
*/
class pageNav {
var $page = null;
var $totalPages = null;
var $link_expression = array(
'startPage'=>"{{link}}.html",
'prePage'=>'{{link}}_{{pre_page}}.html',
'nextPage'=>'{{link}}_{{next_page}}.html',
'endPage'=> "{{link}}_{{end_page}}.html",
'selectPage'=> "'{{link}}_'+this.value+'.html'"
);
function pageNav( $page , $totalPages ) {
$this->totalPages = intval( $totalPages );
$this->page = min($totalPages , $page);
}
function writePagesCounter() {
echo $this->getPagesCounter();
}
function getPagesCounter($link)
{
$html = '';
if ($this->totalPages > 0) {
$html .= "\n 第 " . $this->page . "/" . $this->totalPages ." 页";
$html .=$this->getPagesLimitBox($link);
} else {
$html .= "\n没有记录";
}
return $html;
}
function getPagesLimitBox($link)
{
$html = '';
if ( $this->totalPages > 0) {
$selectPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['selectPage']);
$select = "<select name='' onchange=\"document.location.href=". $selectPageLink ."\">";
$n = $this->totalPages;
for ($i=1;$i<=$n ;$i++ )
{
$option .="<option value='".$i."' ";
if ($i==$this->page) {
$option .="selected";
}
$option .=">".$i."</option>\n";
}
$select .=$option;
$select .="</select>\n";
$html .= "\n 转到第".$select." 页";
}
return $html;
}
function writePagesLinks( $link ) {
echo $this->getPagesLinks( $link );
$this->writePagesCounter();
}
function getPagesLinks( $link )
{
$html = '';
$total_pages = $this->totalPages;
$this_page = $this->page;
$next_page = $this_page+1;
$pre_page = $this_page-1;
if ($this_page > 1) {
$startPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['startPage']);
$prePageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['prePage']);
$html .= "\n<a href='".$startPageLink."' > 首页</a>";
$html .= "\n<a href='".$prePageLink."' > 上一页</a>";
} else {
$html .= "\n<span class=\"pagenav\">首页</span>";
$html .= "\n<span class=\"pagenav\">上一页</span>";
}
if ($this_page < $total_pages) {
$end_page = $total_pages;
$nextPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['nextPage']);
$endPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['endPage']);
$html .= "\n<a href='".$nextPageLink."' > 下一页</a>";
$html .= "\n<a href='".$endPageLink."' > 尾页</a>";
} else {
$html .= "\n<span class=\"pagenav\">下一页 </span>";
$html .= "\n<span class=\"pagenav\">尾页 </span>";
}
return $html;
}
}//end class
?>
/**
* Page navigation class
* bailing
* 2006-11-03
*/
class pageNav {
var $page = null;
var $totalPages = null;
var $link_expression = array(
'startPage'=>"{{link}}.html",
'prePage'=>'{{link}}_{{pre_page}}.html',
'nextPage'=>'{{link}}_{{next_page}}.html',
'endPage'=> "{{link}}_{{end_page}}.html",
'selectPage'=> "'{{link}}_'+this.value+'.html'"
);
function pageNav( $page , $totalPages ) {
$this->totalPages = intval( $totalPages );
$this->page = min($totalPages , $page);
}
function writePagesCounter() {
echo $this->getPagesCounter();
}
function getPagesCounter($link)
{
$html = '';
if ($this->totalPages > 0) {
$html .= "\n 第 " . $this->page . "/" . $this->totalPages ." 页";
$html .=$this->getPagesLimitBox($link);
} else {
$html .= "\n没有记录";
}
return $html;
}
function getPagesLimitBox($link)
{
$html = '';
if ( $this->totalPages > 0) {
$selectPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['selectPage']);
$select = "<select name='' onchange=\"document.location.href=". $selectPageLink ."\">";
$n = $this->totalPages;
for ($i=1;$i<=$n ;$i++ )
{
$option .="<option value='".$i."' ";
if ($i==$this->page) {
$option .="selected";
}
$option .=">".$i."</option>\n";
}
$select .=$option;
$select .="</select>\n";
$html .= "\n 转到第".$select." 页";
}
return $html;
}
function writePagesLinks( $link ) {
echo $this->getPagesLinks( $link );
$this->writePagesCounter();
}
function getPagesLinks( $link )
{
$html = '';
$total_pages = $this->totalPages;
$this_page = $this->page;
$next_page = $this_page+1;
$pre_page = $this_page-1;
if ($this_page > 1) {
$startPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['startPage']);
$prePageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['prePage']);
$html .= "\n<a href='".$startPageLink."' > 首页</a>";
$html .= "\n<a href='".$prePageLink."' > 上一页</a>";
} else {
$html .= "\n<span class=\"pagenav\">首页</span>";
$html .= "\n<span class=\"pagenav\">上一页</span>";
}
if ($this_page < $total_pages) {
$end_page = $total_pages;
$nextPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['nextPage']);
$endPageLink = preg_replace("#\{\{([^\}][^\}]+)\}\}#e", "$\\1",$this->link_expression['endPage']);
$html .= "\n<a href='".$nextPageLink."' > 下一页</a>";
$html .= "\n<a href='".$endPageLink."' > 尾页</a>";
} else {
$html .= "\n<span class=\"pagenav\">下一页 </span>";
$html .= "\n<span class=\"pagenav\">尾页 </span>";
}
return $html;
}
}//end class
?>