您的位置:首页 > 产品设计 > UI/UE

分页函数及最佳统计记录方法

2006-12-22 02:54 387 查看

<?


if(!function_exists(pageft)){ 


function pageft($totle,$displaypg=20,$url=''){


global $page,$firstcount,$pagenav,$_SERVER;


$GLOBALS["displaypg"]=$displaypg;




if(!$page) $page=1;


if(!$url){ $url=$_SERVER["REQUEST_URI"];}


$parse_url=parse_url($url);


$url_query=$parse_url["query"]; 


if($url_query){


$url_query=ereg_replace("(^|&)page=$page","",$url_query);


$url=str_replace($parse_url["query"],$url_query,$url);


if($url_query) $url.="&page"; else $url.="page";


}else {


$url.="?page";


}


$lastpg=ceil($totle/$displaypg); 


$page=min($lastpg,$page);


$prepg=$page-1;


$nextpg=($page==$lastpg ? 0 : $page+1);


$firstcount=($page-1)*$displaypg;


$pagenav="";


if($lastpg<=1) return false;


if($page!=1) $pagenav.=" <a href='$url=1'> <img src="".WWW.BACK."images/first.jpg" width="64" height="16" border="0"></a> "; else  $pagenav.=" <img src="".WWW.BACK."images/first.gif" width="64" height="16" border="0"> ";


if($prepg) $pagenav.="<a href='$url=$prepg'><img src="".WWW.BACK."images/previous.jpg" width="81" height="16" border="0"></a> "; else $pagenav.="<img src="".WWW.BACK."images/previous.gif" width="81" height="16"> ";


if($nextpg) $pagenav.="<a href='$url=$nextpg'><img src="".WWW.BACK."images/next.jpg" width="81" height="16" border="0"></a>"; else $pagenav.="<img src="".WWW.BACK."images/next.gif" width="81" height="16">";


if($page!=$lastpg) $pagenav.=" <a href='$url=$lastpg'><img src="".WWW.BACK."images/last.jpg" width="64" height="16" border="0"></a>"; else $pagenav.=" <img src="".WWW.BACK."images/last.gif" width="64" height="16" border="0">";


$pagenav.=" Goto<select name='topage' style='font-size:9px' size='1' onchange='window.location="$url="+this.value'> ";


for($i=1;$i<=$lastpg;$i++){


if($i==$page) $pagenav.="<option value='$i' selected>$i</option> ";


else $pagenav.="<option value='$i'>$i</option> ";


}


$pagenav.="</select> 共:$lastpg 页$totle 条记录";


}


}


?>

 调用


$temp = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM product where delfag=0 $where LIMIT 1");


$result = mysql_query("SELECT FOUND_ROWS()");


$total = mysql_fetch_row($result);


pageft($total,25,$pageSelf);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐