Home > Backend Development > PHP Tutorial > PHP simple paging code to learn PHP paging principles

PHP simple paging code to learn PHP paging principles

WBOY
Release: 2016-07-25 08:52:49
Original
1115 people have browsed it
  1. include("conn.php"); //Database link, solve it yourself

  2. $sql="select * from news";
  3. $query=mysql_query($ sql);
  4. $all_num=mysql_num_rows($query); //Total number of items
  5. $page_num=3; //Number of items per page
  6. $page_all_num = ceil($all_num/$page_num); //Total number of pages
  7. $ page=empty($_GET['page'])?1:$_GET['page']; //Current page number
  8. $page=(int)$page; //Safe forced conversion
  9. $limit_st = ($page -1)*$page_num; //Start number
  10. //===php paging code key
  11. $sql="select * from news limit $limit_st, $page_num";

  12. $ query=mysql_query($sql);

  13. while($row=mysql_fetch_array($query)){
  14. echo $row['title']." Browse
    ";
  15. }
  16. $px = $page>=$page_all_num ? $page_all_num : $page+1 ;
  17. $ps = $page<=1 ? 1 : $page-1 ;
  18. ?>
  19. Homepage |
  20. Previous page |
  21. Next page |
  22. Last page

Copy code


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