Home  >  Article  >  Backend Development  >  PHP simple paging principle and paging code examples

PHP simple paging principle and paging code examples

WBOY
WBOYOriginal
2016-07-25 08:52:491720browse
  1. /*******Page Principle*************/

  2. //Display the number of records per page
  3. $page_size = 3;
  4. $sql = "select * from message";
  5. $result = mysql_query($sql);

  6. //Total number of records

  7. $num = mysql_num_rows($result);
  8. //Calculation of total number of pages
  9. if($num<= $page_size) { $page_count =1; }
  10. if($num%$page_size) { $page_count = intval($num/$page_size)+1;}
  11. if($num%$page_size==0) { $page_count = $num/$page_size ;}
  12. if( isset($_GET['page']) ){
  13. $page = intval($_GET['page']);
  14. }
  15. else{
  16. $page = 1;
  17. }
  18. $sql_page= "select * from message limit ".($page-1)*$page_size.",$page_size";
  19. $do = mysql_query($sql_page);
  20. while( $re = mysql_fetch_object($ do)){
  21. echo 'Write anything you want';
  22. }
  23. if($page<>1){
  24. echo 'Homepage';
  25. echo 'Previous page';
  26. }
  27. if($page<>$page_count){
  28. echo '
    ';
  29. echo 'Next page';
  30. echo 'Last Night';
  31. echo '< /div>';
  32. }

Copy code


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