亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php分頁(yè)函數(shù)

 更新時(shí)間:2006年07月08日 00:00:00   作者:  
<?php
/*
需求,建立一個(gè)test數(shù)據(jù)庫(kù),在里邊建一個(gè)test表,里面就
只要id字段,輸入一下數(shù)據(jù)就可以啦。。
由于水平有限,難免出錯(cuò)。。
*/
$conn = mysql_connect("localhost","root","");

$maxnum = 2;  //每頁(yè)顯示記錄條數(shù)

mysql_select_db("test", $conn);
$query1 = "SELECT COUNT(*) AS totalrows FROM test ";
$result1 = mysql_query($query1, $conn) or die(mysql_error());
$row1 = mysql_fetch_assoc($result1);
$totalRows1 = $row1['totalrows'];  //數(shù)據(jù)集數(shù)據(jù)總條數(shù)
$totalpages = ceil($totalRows1/$maxnum);//計(jì)算可分頁(yè)總數(shù),ceil()為上舍函數(shù)

if(!isset($_GET['page']) || !intval($_GET['page']) || $_GET['page'] > $totalpages) $page = 1;  //對(duì)3種出錯(cuò)進(jìn)行默認(rèn)處理
//在url參數(shù)page不存在時(shí),page不為10進(jìn)制數(shù)時(shí),page大于可分頁(yè)數(shù)時(shí),默認(rèn)為1
else $page = $_GET['page'];

$startnum = ($page - 1)*$maxnum; //從數(shù)據(jù)集第$startnum條開(kāi)始取,注意數(shù)據(jù)集是從0開(kāi)始的

$query = "SELECT * FROM test LIMIT $startnum,$maxnum";//選擇出符合要求的數(shù)據(jù) 從$startnum條數(shù)據(jù)開(kāi)始,選出$maxnum行
$result = mysql_query($query, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($result);

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分頁(yè)示例</title>
<script language="JavaScript" 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>
<style type="text/css">
a{text-decoration:none;}
a:hover{text-decoration:underline}
table{font-size:12px;}
.tb{background-color:#73BB95}
.tr{background-color:#FFFFFF}
</style>
</head>

<body>
<table width="30%"  border="0" align="center" cellpadding="0" cellspacing="1" class="tb">
  <tr>
    <td height="24"><div align="left">分頁(yè)示例</div></td>
  </tr>
  <?php if($totalRows1) {//記錄集不為空顯示
  do { 
  ?>
  <tr class="tr">
    <td height="24"><div align="center"><?php echo $row['id'];?></div></td>
  </tr>
  <?php }while($row = mysql_fetch_assoc($result));?>
</table>

<table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr><form name="form1">
    <td height="27"><div align="center">
        <?php 
         echo "共計(jì)<font color=\"#ff0000\">$totalRows1</font>條記錄";
         echo "<font color=\"#ff0000\">".$page."</font>"."/".$totalpages."頁(yè) "; 

        //實(shí)現(xiàn) << < 1 2 3 4 5> >> 分頁(yè)鏈接
        $pre = $page - 1;//上一頁(yè)
        $next = $page + 1;//下一頁(yè)
        $maxpages = 4;//處理分頁(yè)時(shí) << < 1 2 3 4 > >>顯示4頁(yè)
        $pagepre = 1;//如果當(dāng)前頁(yè)面是4,還要顯示前$pagepre頁(yè),如<< < 3 /4/ 5 6 > >> 把第3頁(yè)顯示出來(lái)

        if($page != 1) { echo "<a href='".$_SERVER['PHP_SELF']."'><<</a> ";
        echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$pre."'><</a> ";}

        if($maxpages>=$totalpages) //如果總記錄不足以顯示4頁(yè)
        {$pgstart = 1;$pgend = $totalpages;}//就不所以的頁(yè)面打印處理
        elseif(($page-$pagepre-1+$maxpages)>$totalpages)//就好像總頁(yè)數(shù)是6,當(dāng)前是5,則要把之前的3 4 顯示出來(lái),而不僅僅是4
        {$pgstart = $totalpages - $maxpages + 1;$pgend = $totalpages;}
        else{
        $pgstart=(($page<=$pagepre)?1:($page-$pagepre));//當(dāng)前頁(yè)面是1時(shí),只會(huì)是1 2 3 4 > >>而不會(huì)是 0 1 2 3 > >>
        $pgend=(($pgstart==1)?$maxpages:($pgstart+$maxpages-1));
        }

        for($pg=$pgstart;$pg<=$pgend;$pg++){ //跳轉(zhuǎn)菜單
        if($pg == $page) echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$pg\"><font color=\"#ff0000\">$pg</font></a> ";
        else echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$pg\">$pg</a> ";
        }
        if($page != $totalpages)
        {echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'>></a> ";
        echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$totalpages."'>>></a> ";}
        ?>
          <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
          <option value="">選擇</option>
          <?php for($pg1=1;$pg1<=$totalpages;$pg1++) {
           echo "<option value=\"".$_SERVER['PHP_SELF']."?page=$pg1\">".$pg1."</option>";
          }?>
      </select>
    </td></form>
  </tr>
</table>
<?php } else {//記錄集為空時(shí)顯示?>
<tr class="tr">
    <td height="24"><div align="center">沒(méi)有任何記錄</div></td>
  </tr>
  </table>
<?php }?>
</body>
</html>
<?php 
mysql_free_result($result1);
mysql_free_result($result);
?>

相關(guān)文章

最新評(píng)論