Home  >  Article  >  Backend Development  >  php+mysql paging query code (mysql paging example)

php+mysql paging query code (mysql paging example)

WBOY
WBOYOriginal
2016-07-25 08:52:191293browse
  1. /*
  2. * php paging query code
  3. *
  4. */
  5. $perpagenum = 10;//Define how many items to display on each page
  6. $total = mysql_fetch_array(mysql_query("select count(* ) from a"));//Query how many pieces of data there are in the database
  7. $Total = $total[0]; //
  8. $Totalpage = ceil($Total/$perpagenum);//Round up and round up
  9. if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//Four possible states of page
  10. {
  11. $page=1;
  12. }
  13. else
  14. {
  15. $page=$_GET['page'];//If the above four conditions are not met, the value of page is $_GET['page']
  16. }
  17. $ startnum = ($page-1)*$perpagenum;//Start number of items
  18. $sql = "select * from a order by id limit $startnum,$perpagenum";//Query the required number of items
  19. echo $sql. "
  20. ";
  21. $rs = mysql_query($sql);
  22. $contents = mysql_fetch_array($rs);
  23. if($total) If $total is not empty, execute the following statement
  24. {
  25. do
  26. {
  27. $id = $contents['id'];
  28. $name = $contents['name'];
  29. ?>
  30. id:
  31. name:
  32. }
  33. while($contents = mysql_fetch_array($rs));//do....while
  34. $per = $page - 1;//Previous page
  35. $next = $page + 1;//Next page
  36. echo "
    There are ".$Total." records, and each page has ".$perpagenum." records ,Total ".$Totalpage."Pages";
  37. if($page != 1)
  38. {
  39. echo "Homepageecho " Previous page";
  40. }
  41. if( $page != $Totalpage)
  42. {
  43. echo " Next page" ;
  44. echo " Last page";
  45. }
  46. }
  47. elseIf $total is empty, output No message
  48. {
  49. echo "
    No message
    ";
  50. }
  51. ?>
Copy code

Recommended reading:

  • php and ajax no refresh paging code
  • php article paging implementation code
  • php limit page turning (pagination) code
  • PHP paging class with multiple paging methods
  • PHP pagination code for previous page and next page
  • PHP paging code for the first ten pages and the next ten pages
  • Example of simple php pagination code
  • A good php pagination code
  • A paging function: Previous page Next page
  • A useful php paging class
  • php long article pagination code
  • A practical php paging class
  • Fast php paging class


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