php 跳转分页 (部分功能实现)

  看着资料所写,很乱很杂。于是决定自己写一个。自己笨了点,但是花了2个小时,也算写出了个模样了。

  记下来,备忘。

 

文本框跳转那里的功能没有实现,只是实现了旁边数字那里一块的功能。

可以上十页,下十页(页数也随之增减10,如图,页数13,下十页是23),可以点击任何一个数字跳转到那页,当前页数是红色的等功能。

 

关键思路: 主要是每个十页设置一个值。第一个十页,赋予一个值0,第二个十页则为1,以此类推。其他的详见代码。

 

效果图如下:

 

<body>
<table width="700" border="1" align="center">
  <tr>
    <td width="96"><div align="center">ID</div></td>
    <td width="123"><div align="center">TITLE</div></td>
    <td width="127"><div align="center">AUTHOR</div></td>
    <td width="114"><div align="center">NUM</div></td>
  </tr>
 
 <?php
    $linkType = $_GET['linkType'];
    if($_GET['page'] == '')
 {
    $_GET['page'] = 1 ;
 }
 $pageOffset = $_GET['page']%10;
 if($linkType == '')
 {
   $linkType = 0 ;
 }
 if($_GET['page'])
 {
    $sql = "select count(*) as total from tb_info";
    $result = mysql_query($sql);
    $allcount = mysql_result($result,0,"total");
    $pageSize = 1;
    $totalPage = ceil($allcount/$pageSize);
    $offset = ($_GET['page']-1)*$pageSize;
    $result1 = mysql_query("select * from tb_info limit $offset,$pageSize");
    while($arr = mysql_fetch_array($result1))
    {
   
 
?>
  <tr style="background:#FFCCCC;">
    <td><div align="center"><?php echo $arr['id']; ?></div></td>
    <td><div align="center"><?php echo $arr['title']; ?></div></td>
    <td><div align="center"><?php echo $arr['author']; ?></div></td>
    <td><div align="center"><?php echo $arr['num']; ?></div></td>
  </tr>
  <?php
       }
    }
  ?>

</table>
<form  name="form1" method="post" οnsubmit="return chk()">
<table width="700" border="1" align="center">
  <tr>
    <td width="117">帖子统计:<?php echo $allcount; ?>条</td>
    <td width="117">每页显示:<?php echo $pageSize; ?>条</td>
    <td width="85">共有:<?php echo $totalPage; ?>页</td>
    <td width="131">

    <input type="submit" id="Submit" value="跳转" />
    <input type="text" id="te" name="te" size="3" />页
    <input type="hidden" id="hid" name="hid" value="<?php echo $allcount; ?>" />

   
    </td>
    <td width="193">
<?php
    $link = $linkType*10;
   
    echo '<a href="jump.php?linkType=0&page=1"><img src="images/01.jpg" width="8" border="0" height="9" border="0" title="首页"></a>&nbsp;';
 if($linkType != 0)
 {
        echo '<a href="jump.php?linkType='.($linkType-1).'&page='.(($linkType-1)*10+$pageOffset).'"><img src="images/02.jpg" width="8" border="0" height="9" border="0" title="上十页"></a>&nbsp;';
 }
 
 $offset2 = $linkType*10;
 $result2 = mysql_query("select * from tb_info limit $offset2,10");
 $num = mysql_num_rows($result2);
 
    for($i=1;$i<=$num;$i++)
    {
       $pagination = $link + $i;
    echo "<a href='jump.php?page=".$pagination."&linkType=".$linkType."'>";
    if($_GET['page'] ==  $pagination)
    {
       echo "<span style='color:#ff0000;'>".$pagination."</span>" ;
    }
    else
    {
         echo $pagination;
    }
    echo "</a>";
   
    }
?>    </td>
    <td width="17">
 <?php
 if(($linkType+1)<=($allcount/10))
 {
    echo '<a href="jump.php?linkType='.($linkType+1).'&page='.(($linkType+1)*10+$pageOffset).'"><img src="images/03.jpg" width="8" border="0" height="9" border="0" title="下十页"></a>&nbsp;';
 }
 else
 {
  echo "";
 }
 ?>     </td>
  </tr>
</table>

</form>
</body>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值