php数据库改分页类 php mysql 分页( 四 )


echo "TABLE style=\"MARGIN-BOTTOM: 20px\" cellSpacing=0 cellPadding=0 width=100% \n";
echo "TBODY\n";
echo "TR\n";
echo "TD style=\"PADDING-TOP: 5px\" vAlign=top align=left width=80\n";
//rating_bar($title[$a],5);
echo "/TD\n";
echo "TD style=\"PADDING-TOP: 5px\" align=left width=100%A title=$hotelname[$a] style=\"FONT-SIZE: 14px\" href=https://www.04ip.com/post/#$hotelname[$a]/A/n";
echo "/TD/TR\n";
echo " TR\n";
echo "TD/TD\n";
echo "TD style=\"PADDING-LEFT: 0px\"\n";
echo "IMG src=https://www.04ip.com/"images/comment.gif\"推荐人数:($countpeople[$a]) |\n";
echo "SPAN平均分:STRONG/STRONG (".$count."票) | 评论数:()/SPAN\n";
echo "/TD/TR/TBODY/TABLE\n";
}
echo "TABLE style=\"MARGIN-TOP: 30px\" cellSpacing=0 cellPadding=0 width=\"100%\"";
echo "";
echo "TBODYTRTD colSpan=3 height=20";
echo "DIV align=center";
echo "P align=leftFONT color=red第".$page."页/总".$pages."页 | 总".$numrows."条/FONT | ";
if ($page1) echo "a onclick=\"viewpage(".$first.")\" href='https://www.04ip.com/post/#'首页/a | ";
if ($page1) echo "a onclick=\"viewpage(".$prev.")\" href='https://www.04ip.com/post/#'上页/a | ";
if ($page$pages) echo "a onclick=\"viewpage(".$next.")\" href='https://www.04ip.com/post/#'下页/a | ";
if ($page$pages) echo "a onclick=\"viewpage(".$last.")\" href='https://www.04ip.com/post/#'尾页/a";
echo "转到第 INPUT maxLength=3 size=3 value=https://www.04ip.com/post/1 name=goto_page 页 INPUT hideFocus onclick=/"viewpage(document.all.goto_page.value)\" type=button value=https://www.04ip.com/post/Go name=cmd_goto";
echo "/P/DIV/TD/TR/TBODY/TABLE";
php 分页类怎么用?。?/h2>?php
class Page {
private $total_rows;//数据库总条数
private $per_page_rows;//每页显示条数
private $limit;
private $uri;
private $total_pages;//总页数
private $config=array("header"="记录条数","prev"="上一页","next"="下一页","first"="首 页","last"="尾 页");
private $list_length=8;
public function __construct($total_rows,$per_page_rows=10,$url_args){
$this-total_rows=$total_rows;
$this-per_page_rows=$per_page_rows;
$this-uri=$this-get_uri($url_args);
$this-page = !empty($_GET['page']) ? $_GET['page'] : 1;
$this-total_pages=ceil($this-total_rows/$this-per_page_rows);
$this-limit=$this-set_limit();
}
private function set_limit() {
return "limit ".($this-page-1)*$this-per_page_rows.",{$this-per_page_rows}";
}
private function get_uri($url_args) {
$url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"],"?") ? "" : "?").$url_args;
$parse=parse_url($url);
if (isset($parse['query'])) {
parse_str($parse['query'],$params);//把url字符串解析为数组
unset($params['page']);//删除数组下标为page的值
$url=$parse['path'].'?'.http_build_query($params);//再次构建url
}
return $url;
}
public function __get($args) {
if ($args=="limit") {
return $this-limit;
}else{
return null;
}
}
private function start_page(){
if ($this-total_rows==0) {
return 0;
}else{
return (($this-page-1)*$this-per_page_rows)+1;
}
}
private function end_page(){
return min($this-page*$this-per_page_rows,$this-total_rows);
}
private function go_first() {
$html="";
if ($this-page==1) {
$html.="nbsp;{$this-config['first']}nbsp;";
}else{
$html.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page=1'{$this-config['first']}/anbsp;";
}
return $html;
}
private function go_prev() {
$html="";
if ($this-page==1) {
$html.="nbsp;{$this-config['prev']}nbsp;";
}else{
$html.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page={$this-page}-1'{$this-config['prev']}/anbsp;";

推荐阅读