今天写代码遇到写一个分页,而以前写的分页自己又不太满意,就重新写了一个。
效果如图:
写完后,感觉代码太多,不太完善,不过功能实现了
<?php switch ($page) { case 1: echo '<div class="movie_page"><a href="?page=1#all">首页</a><span >1</span><a href="?page=2#all" >2</a><a href="?page=3#all"> 3</a> <a href="?p age=4#all">4</a> <a href="?page=5#all">5</a> <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>1</font><font>/</font><font>'.$total_page.'</font></div> </div>'; break; case 2: echo '<div class="movie_page"><a href="?page=1#all">首页</a><a href="?page=1#all">1</a><span >2</span><a href="?page=3#all">3</a> <a href="?pa ge=4#all">4</a> <a href="?page=5#all">5</a> <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>2</font><font>/</font><font>'.$total_page.'</font></div> </div>'; break; case 3: echo '<div class="movie_page"><a href=?page=1#all"">首页</a><a href="?page=1#all">1</a><a href="?page=2#all">2</a><span >3</span><a href="?pag e=4#all">4</a> <a href="?page=5#all">5</a> <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>3</font><font>/</font><font>'.$total_page.'</font></div> </div>'; break; case 4: echo '<div class="movie_page"><a href="?page=1#all">首页</a><a href="?page=1#all">1</a><a href="?page=2#all">2</a><a href="?page=3#all">3</ a><span >4</span> <a href="?page=5#all">5</a> <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>4</font><font>/</font><font>'.$total_page.'</font></div> </div>'; break; case 5: echo '<div class="movie_page"><a href="?page=1#all">首页</a><a href="?page=1#all">1</a><a href="?page=2#all">2</a><a href="?page=3#all">3</a> <a href="?page=4#all">4</a><span >5</span> <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>5</font><font>/</font><font>'.$total_page.'</font></div> </div>'; break; default: echo '<div class="movie_page"><a href="?page=1#all">首页</a><a href="?page=1#all"><span>1</span onclick="showMovieChange("'.$arr_cinema[($page- 1)*$pageSize][0].'");"></a><a href="?page=2#all">2</a><a href="?page=3#all">3</a> <a href="?page=4#all">4</a> <a href="?page=5#all">5</a > <a href="?page='.$total_page.'#all">末页</a> <div class="movie_page_total"><font>1</font><font>/</font><font>'.$total_page.'</font></div> </div>'; } ?>
其中的#all,是为了点击页码,页面刷新时加的锚点,我用的是Id。
代码太多,而且还不通用,先记下来,以后有时间写成一个分页类。
加油,↖(^ω^)↗!