php 分页实现

$url=$_SERVER[‘REQUEST_URL’]; //获得当前请求的URL

$url=parse_url($url);//将获得的URL解析成有固定键值的数组

$url=$url[‘path’];//获得路径

 

$pageSize=10;//设置一页显示的条数

if(isset($_GET[‘page’]))

$currentPage=$_GET[‘page’];

else

   $currentPage=1;

 

$conn=@mysql_connnect(“localhost”,”root”,”root”)or die (“数据库连接失败”);

mysql_select_db(“test”,$conn);

mysql_query(“set names ‘utf-8’”);

$sql=”select * from policyinfo”;

$query=mysql_query($sql);

$totalSize=mysql_num_rows($query);

$totalPage=ceil($totalSize/$pageSize);//向上取整函数

$from=($currentPage-1)* $pageSize;

$sql=”select * from policyinfo limit $from, $pageSize”;

$query=mysql_query($sql);

While($row=mysql_fetch_array($query))

{

显示数据

}

//下一页 上一页 首页 尾页按钮

<table style="width: 100%;">

<tr>

<td align="right">

    <div style="line-height: 33px; float: right">

<?php

        if ($currentPage==1)

           {

                          ?>

                             <input type="button" name="FirstPage" value="首页" id="FirstPage" disabled>

 

                                <input type="button" name="PreviousPage" value="上一页"

                                   id="PreviousPage" disabled>

                        <?php

                             }

                             else {

                         ?>

 

                                <input type="button" name="FirstPage" value="首页" id="FirstPage"

                                  onclick="javascript:window.location.href=‘<?php echo $url."?page=1";?>">

 

                                <input type="button" name="PreviousPage" value="上一页"

                                   id="PreviousPage" class="btbuttom"

                                  onclick="javascript:window.location.href=‘<?php echo $url."?page=".($currentPage-1);?>">

                            <?php

                             }

                             if ($currentPage>=$totalPage)

                             {

                          ?>

                                  <input type="button" name="NextPage" value="下一页" id="NextPage" disabled>

 

                                <input type="button" name="LastPage" value="尾页" id="LastPage" disabled>

                        <?php

                             }

                             else {

                         ?>

                                   <input type="button" name="NextPage" value="下一页" id="NextPage"

                                       onclick="javascript:window.location.href=‘<?php echo $url."?page=".($currentPage+1);?>">

   

   

                                   <input type="button" name="LastPage" value="尾页" id="LastPage"

                                       onclick="javascript:window.location.href=‘<?php echo $url."?page=".$totalPage;?>">

                         <?php

                             }

                         ?>    

                         </div>

                     </td>

 

                  </tr>

                                          </table>

php 分页实现,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。