<?php 
/////////////////////////////////////////////////////////
/////              分页函数（page.inc.php）         /////
/////$nums         传入列表总数                     /////
/////$limit        传入每页限制数                   /////
/////$url          传入上下页地址                   /////
/////$pagetype     判断页数标记符                   /////
/////////////////////////////////////////////////////////
function page($nums,$limit,$url,$pagetype,$list){

 
//计算总页数 $numpage
$numPage = $nums/$limit;
   if($nums<$limit){
   $numPage = 1;
   }else{
   for($i=0;$i<$numPage;$i++){
		$y = $i+1;
		if($y>$numPage){
		$numPage = $y;
			}
		}
	}
   //计算当前页  $page
	if($pagetype == NULL){
	$pagetype  =  'page';
	$getpage   =  $_GET['page'];
	}else{
	$pagetype  =  $pagetype;
	$getpage   =  $_GET["$pagetype"];
	}
if($getpage==NULL){
		$page      =  1;
	}elseif($getpage<=0){
		$page      =  1;
	}elseif($getpage>$numPage){
		$page      =  1;
	}else{
		$page      =  $getpage;
	}
//区分翻页
if($page!=1){
			$u      =    $page-1;
			$up     =    '<a href='.$url.$pagetype.'='.$u.'>上页</a>';
		}else{
			$up     =    '上页';
		}
 if($page!=$numPage){
			$d      =    $page+1;
			$down   =     '<a href='.$url.$pagetype.'='.$d.'>下页</a>';
		}else{
			$down   =    '下页';
	     }	  
if($list == 'NO' ){
		$pages = $up.'-'.$down;
	}elseif($list=='view'){
		$jumpMeun .= '<script type="text/javascript">function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
  if (restore) selObj.selectedIndex=0;
}</script><form action="" method="get"><select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu(\'parent\',this,1)">';
for($i=1;$i<=$numPage;$i++){
if($i == $_GET[$pagetype]){
		$mr = ' selected="selected"';
	}else{
		$mr = '';
	}
		$jumpMeun.='<option value="'.$url.$pagetype.'='.$i.'"'.$mr.' >'.$i.'/'.$numPage.'</option>';
	}
	$jumpMeun .=' </select></form>';
	$pages = '<table border="0" class="page"><tr><td class="startpage"><a href='.$url.$pagetype.'=1>首页</a></td><td class="uppage">'.$up.'</td><td class="center" valign="middle">'.$jumpMeun.'</td><td class="downpage">'.$down.'</td><td class="endpage"><a href='.$url.$pagetype.'='.$numPage.'>末页</a></td></tr></table>';
}else{
	$pages = '第'.$page.'/'.$numPage.'页|共'.$nums.'条记录<br>'.$up.'-'.$down;
}	

return $pages;
}
function pagen($nums,$limit){
$numPage = $nums/$limit;
		if($nums<$limit){
		$numPage = 1;
   }else{
	for($i=0;$i<$numPage;$i++){
		$y = $i+1;
		if($y>$numPage){
			$numPage = $y;
			}
		}
	}
  return $numPage;
}
