<?php

//计算当前页开始数
//$pagenum 页数
//$num     总数
function page_top($pagenum,$num){
	$pages=ceil($num/$pagenum);

	if (isset($_GET['page'])) {
		$page=intval($_GET['page']);
		$page > $pages && $page = $pages;
		$page <= 0 && $page = 1;
	}else $page=1;

	$page = $page - 1;

	return $page;
}


//$page   当前页数
//$pagenum   总页数
//$num     总数
//$str     附加的字符串
function page_foot($page,$pagenum,$num){
	$ceil =  ceil($num/$pagenum);
	$page++;
	
	$str = $_SERVER['QUERY_STRING'];
		
	if (strpos($str,'&page')) $str = substr($str,0,strpos($str,'&page'));

	$page_foot = ' <form style="margin:0px;padding:0px;" action="?'.$str.'" method="GET" name="form1" id="form1" >';
	$page_foot .='<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>';

	$page_foot .= "<td width='30%' align='center'>共&nbsp;".($ceil)."&nbsp;页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$num."&nbsp;条记录 </td>";
	//$ceil = $ceil-1;
	$page_foot .="<td width='40%'align='center'>";
	$page>1 ?  $page_foot .=  "<a href=?".$str."&page=1>首页</a>" : $page_foot .=  "首页" ;
	$page>1 ? $page_foot .= "&nbsp;&nbsp;&nbsp; <a href=?".$str."&page=".($page-1).">上一页</a> "  : $page_foot .=  "&nbsp;&nbsp;&nbsp;上一页" ;
	$page<$ceil ?  $page_foot .= "&nbsp;&nbsp;&nbsp; <a href=?".$str."&page=".($page+1).">下一页</a> "  : $page_foot .=  " 下一页 " ;
	$page<$ceil ?  $page_foot .= "&nbsp;&nbsp;&nbsp; <a href=?".$str."&page=".$ceil.">末页</a> " : $page_foot .=  " 末页 " ;
	;
	$page_foot .="</td>";
	$page_foot .="<td width='30%' align='center'>";
	$page_foot .=  '当前&nbsp;'.$page.'&nbsp;页 ';

	$page_foot .= '&nbsp;&nbsp;&nbsp; 去<input type="text"  style="width:30px;height:20px" name="page"> 页 &nbsp;&nbsp;&nbsp;';
	$page_foot .= '<input type="submit" value="GO"  style="BACKGROUND: #FF7F00; FONT-SIZE: 8pt"> 
	</td>
  </tr>
</table></form>';

	return $page_foot;
}



?>