PHP头条
热点:

php分页显示函数 源代码


php分页显示函数 源代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>google分页</title>
<meta name="keywords" content="仿google php分页程序 " />
<meta name="description" content="仿google php分页程序" />
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; }
div { height: auto; width: 800px; margin: 10px auto; line-height:20px; }

/*CSS manu style pagination*/

.manu {
 PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
.manu A {
 BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; TEXT-DECORATION: none
}
.manu A:hover {
 BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu A:active {
 BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu .current {
 BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; BACKGROUND-COLOR: #036cb4
}
.manu .disabled {
 BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid
}

-->
</style>
</head>

<body>
<?php

require('web_page.php'); //包含分页程序


//数据库配置
$mysql_host = 'localhost'; //数据库服务器
$mysql_user = 'root'; //数据库用户名
$mysql_pass = '123456'; //数据库密码
$mysql_db = 'test'; //数据库名


//连接mysql数据库

$link = mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die ('连接MYSQL服务器出错');
  mysql_select_db($mysql_db,$link) or die ('连接MYSQL数据库出错');


//分页开始

$sql_page = "select news_id,news_title from cms_news order by news_id desc";
$sql = mysql_query($sql_page);
$num = mysql_num_rows($sql);  //总条数
$max = 1;  //每页条数
$pagenum = ceil($num/$max);  //可分页数
if(!isset($_GET['page']) or !intval($_GET['page']) or !is_numeric($_GET['page']) or $_GET['page'] > $pagenum){
 $page = 1; //当页数不存在 不为十进制数 不是数字 大于可分页数 为1
}else{
 $page = $_GET['page'];  //当前页数
}
$min = ($page-1)*$max;  //当前页从$min条开始

$sql = "{$sql_page} limit $min,$max";


echo '<div>';
if($num){
 $sql = mysql_query($sql);
 for(;$row = mysql_fetch_array($sql);){
  echo '<li><a href="show.php?id='.$row['news_id'].'">'.$row['news_title'].'</a></li>';
 }
}else{
 echo '<li>暂无</li>';
}
echo '</div>';

//mysql_free_result($sql); //释放资源

?>

<div class="manu"><?php web_page(""); //调用输出分页,引用你的页面其他参数 如:web_page("&class=2&news=6") ?></div>

<?php
//分页结束
mysql_close();
?>

</body>
</html>

上面为调用方法下面为分页程序

<?php

 

function web_page($pageurl="", $pageselect = true){

 global $page,$num,$pagenum; //当前页数 总页数 可分页数

 echo "共 $num 条记录,";

 $uppage = $page - 1;  //上一页
 $downpage = $page + 1;  //下一页
 $lr = 5;  //显示多少个页数连接
 $left = floor(($lr-1)/2);  //左显示多少个页数连接
 $right = floor($lr/2);  //右显示多少个页数连接

 //下面求开始页和结束页
 if($page <= $left){  //如果当前页左不足以显示页数
  $leftpage = 1;
  $rightpage = (($lr<$pagenum)?$lr:$pagenum);
 }elseif(($pagenum-$page) < $right){  //如果当前页右不足以显示页数
  $leftpage = (($pagenum<$lr)?1:($pagenum-$lr+1));
  $rightpage = $pagenum;
 }else{  //左右可以显示页数
  $leftpage = $page - $left;
  $rightpage = $page + $right;
 }

 //前$lr页和后$lr页
 $qianpage = (($page-$lr) < 1?1:($page-$lr));
 $houpage = (($page+$lr) > $pagenum?$pagenum:($page+$lr));

 //输出分页
 if($page != 1){
  echo "<a title="首页" href="".$_SERVER['PHP_SELF']."?$pageurl"><<</a> <a title="上一页" href="".$_SERVER['PHP_SELF']."?page=$uppage$pageurl"><</a> ";
 }else{
  echo "<span class='disabled'><<</span><span class='disabled'><</span> ";
 }

 for($pages = $leftpage; $pages <= $rightpage; $pages++){
  if($pages == $page){
   echo "<span class='current'>$pages</span> ";
  }else{
   echo "<a href="?page=$pages$pageurl">$pages</a> ";
  }
 }

 if($page != $pagenum){
  echo "<a title="下一页" href="".$_SERVER['PHP_SELF']."?page=$downpage$pageurl">></a> <a title="末页" href="".$_SERVER['PHP_SELF']."?page=$pagenum$pageurl">>></a>";
 }else{
  echo "<span class='disabled'>></span><span class='disabled'> >></span> ";
 }

 //跳转
 $javapage = <<<EOM
<script language="javascript">
function web_page(targ,selObj,restore){
 eval("self"+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}
</script>
EOM;
 echo $javapage;
 if ($pageselect){
  echo "跳转至 <select onchange="web_page('parent',this,0)" name="menu1">";
  for($pages = 1; $pages <= $pagenum; $pages++){
   $selected = ($pages == $page)?" selected="selected"":"";
   echo "<option value="".$_SERVER['PHP_SELF']."?page=$pages$pageurl"$selected> $pages</option>";
  }
  echo "</select> 页";
 }

}
?>

www.phpzy.comtrue/php/10475.htmlTechArticlephp分页显示函数 源代码 php分页显示函数 源代码 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head meta http-equiv...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐