Home  >  Article  >  Backend Development  >  PHP paging principle analysis and PHP paging code design

PHP paging principle analysis and PHP paging code design

WBOY
WBOYOriginal
2016-07-25 08:52:491409browse
  1. //php分页代码

  2. // bbs.it-home.org
  3. include("conn.php");
  4. $pagesize=5;//每页显示记录
  5. $startrow=0;//当前页记录头
  6. if(empty($_GET['pageno'])){
  7. if($startrow==0){
  8. $pageno=$startrow+1;
  9. }
  10. }else{
  11. $pageno=$_GET['pageno'];
  12. $startrow=($pageno-1)*$pagesize;
  13. }
  14. $sql="select * from test";
  15. $result1=mysql_query($sql,$conn);
  16. $resultcount=mysql_num_rows($result1);
  17. if($resultcount%$pagesize==0){
  18. $maxpage=$resultcount/$pagesize;
  19. }else{
  20. $maxpage=ceil($resultcount/$pagesize);
  21. }

  22. $result=mysql_query("select * from test LIMIT $startrow,$pagesize");

  23. while($row=mysql_fetch_array($result)){
  24. echo $row["name"].'
    ';
  25. }
  26. ?>

  27. 首页
  28. 上一页
  29. 下一页
  30. 末页

复制代码


Statement:
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