Example of simple php pagination code

WBOY
Release: 2016-07-25 09:05:23
Original
967 people have browsed it
  1. php make page list
  2. /*
  3. * Created on 2010-4-17
  4. * @link http://bbs.it-home.org
  5. * Order by Kove Wong
  6. */
  7. $link=MySQL_connect('localhost','root','9922233344455');
  8. mysql_select_db('pagelist');
  9. mysql_query('set names gbk');

  10. $Page_size=10;

  11. $result=mysql_query('select * from v_char');

  12. $count = mysql_num_rows($result);
  13. $page_count = ceil($count/$Page_size);

  14. $init=1;

  15. $page_len=7;
  16. $max_p=$page_count;
  17. $pages=$page_count;

  18. //判断当前页码

  19. if(empty($_GET['page'])||$_GET['page']<0){
  20. $page=1;
  21. }else {
  22. $page=$_GET['page'];
  23. }

  24. $offset=$Page_size*($page-1);

  25. $sql="select * from v_char limit $offset,$Page_size";
  26. $result=mysql_query($sql,$link);
  27. while ($row=mysql_fetch_array($result)) {
  28. ?>
  29. }
  30. $page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数
  31. $pageoffset = ($page_len-1)/2;//页码个数左右偏移量

  32. $key='

    ';
  33. $key.="$page/$pages "; //第几页,共几页
  34. if($page!=1){
  35. $key.="第一页 "; //第一页
  36. $key.="上一页"; //上一页
  37. }else {
  38. $key.="第一页 ";//第一页
  39. $key.="上一页"; //上一页
  40. }
  41. if($pages>$page_len){
  42. //如果当前页小于等于左偏移
  43. if($page<=$pageoffset){
  44. $init=1;
  45. $max_p = $page_len;
  46. }else{//如果当前页大于左偏移
  47. //如果当前页码右偏移超出最大分页数
  48. if($page+$pageoffset>=$pages+1){
  49. $init = $pages-$page_len+1;
  50. }else{
  51. //左右偏移都存在时的计算
  52. $init = $page-$pageoffset;
  53. $max_p = $page+$pageoffset;
  54. }
  55. }
  56. }
  57. for($i=$init;$i<=$max_p;$i++){
  58. if($i==$page){
  59. $key.=' '.$i.'';
  60. } else {
  61. $key.=" ".$i."";
  62. }
  63. }
  64. if($page!=$pages){
  65. $key.=" 下一页 ";//下一页
  66. $key.="最后一页"; //最后一页
  67. }else {
  68. $key.="下一页 ";//下一页
  69. $key.="最后一页"; //最后一页
  70. }
  71. $key.='';
  72. ?>
  73. ID 文章标题
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template